How can I convert an NSDate to a Unix timestamp in Objective-C?
Unix epoch timestamps10 digit epoch time format surrounded by brackets (or followed by a comma). The digits must be at the very start of the message. For example, [1234567890] or [1234567890, other] followed by the rest of the message. 13 digit epoch time.
Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC.
php - How to convert a 13 digit Unix Timestamp to Date and time? - Stack Overflow.
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 believe - [NSDate timeIntervalSince1970]
is what you want. Jan 1, 1970 is the date of the Unix epoch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With