#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSDate *now = [NSDate date];
//时间指针格式
NSLog(@"The time for now is :%p. \n", now);
//时间数据格式
NSLog(@"The time for now is %@ \n", now);
//计算1970年1月1日 12点中到现在的时间
double seconds = [now timeIntervalSince1970];
NSLog(@"From 1970-01-01 12:00 to now is :%f seconds\n", seconds);
}
return 0;
}
Result:
2018-03-10 14:15:08.101631+0800 TOCNSDatea[37619:12858536] The time for now is :0x10045f2c0.
2018-03-10 14:15:08.101949+0800 TOCNSDatea[37619:12858536] The time for now is Sat Mar 10 14:15:08 2018
2018-03-10 14:15:08.101967+0800 TOCNSDatea[37619:12858536] From 1970-01-01 12:00 to now is :1520662508.101608 seconds
Program ended with exit code: 0