开发者

How to convert NSDate into Unix timestamp in Objective C/iPhone? [duplicate]

This question already has answers here: How to convert NSDate into unix time开发者_如何学Gostamp iphone sdk? (10 answers) Closed 8 years ago.

How can I convert an NSDate to a Unix timestamp in Objective-C?


I believe - [NSDate timeIntervalSince1970] is what you want. Jan 1, 1970 is the date of the Unix epoch.


NSDate *date = [NSDate date];
NSTimeInterval ti = [date timeIntervalSince1970];

NSTimeInterval is typedefed as a double, defined in seconds. If you want it in integer form, just cast the result to a long and use that instead, but this gives more precision.


I like properties.

NSDate.date.timeIntervalSince1970;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜