iOS开发-NSDate使用

时间戳是自 1970 年 1 月 1 日(00:00:00 GMT)至当前时间的总秒数。它也被称为 Unix 时间戳(Unix Timestamp)。

下面是iOS中时间戳 与 时间之间的转换方法:

1.NSDate转换为时间戳

NSDate *localDate = [NSDate date];
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[localDate timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //时间戳的值

2.把时间戳转换为NSDate

NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];
NSLog(@"1363948516  = %@",confromTimesp);

  

原文地址:https://www.cnblogs.com/feiling/p/4915533.html