【发布时间】:2013-07-09 02:17:47
【问题描述】:
下面是某个服务器返回的时间戳字符串
dateFromServer = 2013-07-08 16:45:03Z
我正在执行以下操作以将其转换为 NSDate
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy'-'MM'-'dd' 'HH':'mm':'ss'Z'"];
NSTimeZone *destinationTimeZone = [NSTimeZone systemTimeZone];
[format setTimeZone:destinationTimeZone];
dateFromServer = [dateFromServer stringByReplacingOccurrencesOfString:@"T" withString:@" "];
NSDate *oldTime = [format dateFromString:dateFromServer];
我得到了
oldTime is 2013-07-08 20:45:03 +0000
原来的时间戳好像加了+4
为什么会这样,我该如何避免这种情况?
【问题讨论】:
-
这是时区不同。
标签: iphone ios objective-c nsdate nstimezone