Objective-C 无效的双精度变量值
我有以下代码...
double time = [[NSDate date] timeIntervalSince1970];
double startTime = time;
double endTime = time;
当我运行代码时,startTime
和 endTime
彼此甚至不接近。例如,startTime
为 4378480
,endTime
为 1883506224
。
为什么两个时间值之间有如此大的差异?
I have the following piece of code...
double time = [[NSDate date] timeIntervalSince1970];
double startTime = time;
double endTime = time;
When I run the code, the startTime
and endTime
are not even close to each other. For example, the startTime
is 4378480
and the endTime
is 1883506224
.
Why is there such a difference between the 2 time values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以链接用于输出值的代码吗?请记住您需要在格式化程序中使用 %f 而不是 %d。上面应该是等效的,因为两者都指向相同的值
Can you link the code you are using to output the values, remember you need to use %f not %d in the formatter. The above should be equivalent as both are pointing to the same value
没关系,我遇到的问题是使用了不正确的 NSLog 字符。
当它应该是这样的时候。
Never mind, the problem I was having was using the incorrect NSLog character.
When it was supposed to be this.
首先,对所有变量类型使用 NSTimeInterval,而不是 double。
接下来 - 显示您用来打印值的代码。我怀疑您使用了错误的变量类型格式(因为时间间隔总是有小数部分),并且因此有效地打印了垃圾。
First, use
NSTimeInterval
, notdouble
, for all the variable types.Next -- show the code you are using to print the values. I suspect you are using the wrong format for the variable type (as time intervals always have a decimal component) and are effectively printing garbage as a result.