How can I convert an NSDate to a Unix timestamp in Objective-C?
+1
A:
NSDate *date = [NSDate date];
NSTimeInterval ti = [date timeIntervalSince1970];
NSTimeInterval
is typedefed as a float, 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.
Ed Marty
2010-06-11 13:56:29
+2
A:
I believe - [NSDate timeIntervalSince1970]
is what you want. Jan 1, 1970 is the date of the Unix epoch.
Brian
2010-06-11 13:57:54