我的格式来自我的webapp日期和时间:
2012-02-23T23:25:22Z
我试过不同的格式但没有成功。
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];
如何设置NSDateFormater以将此字符串转换为NSDate?
答案 0 :(得分:5)
<强>更新强>
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
但是你的Z代表什么......我想这不是时区
答案 1 :(得分:2)
您正在使用RFC3339日期时间。
Apple使用此recommendation:
[rfc3339DateFormatter setLocale:enUSPOSIXLocale];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];