timeIntervalSinceDate返回什么时间单位?


73

timeIntervalSinceDate返回什么时间单位?是秒,毫秒还是其他?

文档说它返回一个NSTimeInterval,但是那个值是什么时间单位?


3
来自NSTimeInterval参考:用于指定时间间隔,以秒为单位。typedef double NSTimeInterval;。NSTimeInterval总是以秒为单位
— albertamg

Answers:


94

它返回秒数,作为一个NSTimeInterval值。

从此文档页面:

NSTimeInterval总是以秒为单位;在10,000年的时间范围内,其精度可达到亚毫秒级。


5
NSTimeInterval不是一个真正的对象。这只是一个双值。
— BoltClock

4
其实,NSTimeInterval是始终以秒为单位。
— GarlicFries

1
如果以秒为单位,如何得到毫秒?
— Moshe

6
由于1秒= 1000ms,因此[NSDate timeIntervalSinceDate:foo] * 1000应为毫秒。
— esqew

1
@esqew-啊,我忘记了。NSTimeInterval有一个小数点-以及其后的数字。
— Moshe

7

那么NSDate 文档显示函数原型为:

- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate

Foundation Data Types文档指出:

NSTimeInterval总是以秒为单位;在10,000年的时间范围内,其精度可达到亚毫秒级。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.