Unix Timestamp in Objective-C
Look up the current epoch time and convert between Unix seconds and UTC dates in Objective-C.
Get the current timestamp
#import <Foundation/Foundation.h>
#include <math.h>
int main(void) {
@autoreleasepool {
printf("%lld\n", (long long)floor(NSDate.date.timeIntervalSince1970));
}
}Timestamp to date
#import <Foundation/Foundation.h>
int main(void) {
@autoreleasepool {
NSDate *date = [NSDate dateWithTimeIntervalSince1970:1700000000];
NSISO8601DateFormatter *format = [NSISO8601DateFormatter new];
puts([format stringFromDate:date].UTF8String);
}
}Date to timestamp
#import <Foundation/Foundation.h>
#include <math.h>
int main(void) {
@autoreleasepool {
NSISO8601DateFormatter *format = [NSISO8601DateFormatter new];
NSDate *date = [format dateFromString:@"2023-11-14T22:13:20Z"];
printf("%lld\n", (long long)floor(date.timeIntervalSince1970));
}
}Open 1700000000 in the converter
Current Unix time
Seconds—
Milliseconds—
- UTC
- —
- My time zone
- —
Free to use. Your input stays in this browser.
How to use it
- Copy the current-time example into your Objective-C environment to read Unix seconds.
- Run the second example to display 1700000000 as a UTC date.
- Run the last example to convert that date back into seconds.
Use NSDate’s timeIntervalSince1970 for Unix seconds. Its reference-date API instead measures from 2001. NSISO8601DateFormatter reads and writes explicit UTC timestamps.