开发者

Is there a way to get timeIntervalSince1970 without using NSDate?

I'm trying to avoid creat开发者_如何学Going an NSDate object since my code is heavy in needing the 'current time'. I end up calling [[NSDate date] timeIntervalSince1970] a lot. Is there any way to get the time interval without instantiating the object?


CFAbsoluteTimeGetCurrent gives you similar accuracy - no object required.

CFAbsoluteTimeGetCurrent uses a different base (or reference date), so you will have to initially determine the offset or the bases if you need to use another reference date (e.g. relative to some time in 1970).


NSTimeInterval interval = [NSDate timeIntervalSinceReferenceDate];


you deleted your comment regarding an option with more accuracy than CFAbsoluteTimeGetCurrent: try gettimeofday

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜