iOS中计算时间戳的方式很简单,通过NSDate的timeIntervalSince1970即可计算,代码如下:
NSString *dateString = @"2016-09-21 9:20:10";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *mydate=[formatter dateFromString:dateString];
NSTimeInterval myInterval = [mydate timeIntervalSince1970];
NSLog(@"%@---%f",formate,interval);
NSLog(@"%@---%f",mydate,myInterval);
输出结果:
**2016/09/22---1474505458.993212**
**2016-09-21 01:20:10 +0000---1474420810.000000**