我有个约会,比如:
2014-01-31 17:40:56如何用毫秒的时间戳来转换它呢?
结果是1391170256309,它是由PHP计算的。
如何在目标C中将2014-01-31 17:40:56转到1391170256309?
发布于 2014-03-08 05:07:03
这对你想做的事有用吗?
NSString * dateString = @"2014-01-31 17:40:56";
NSDateFormatter *df=[[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[df setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
NSDate *date = [df dateFromString:dateString];
NSTimeInterval since1970 = [date timeIntervalSince1970]; // January 1st 1970
double result = since1970 * 1000;发布于 2014-03-08 04:59:39
NSDate有一个用于此特定场景的工厂方法。
- (NSTimeInterval)timeIntervalSince1970在所谓的“时代时间”中计算的结果。
发布于 2014-03-08 05:12:40
下面是用于NSDate到->毫秒的示例代码:
NSTimeInterval seconds = [NSDate timeIntervalSinceReferenceDate];
double milliseconds = seconds*1000;备注:参考日期为2001年1月1日,因此格林尼治时间乘以1000
https://stackoverflow.com/questions/22265141
复制相似问题