【发布时间】:2023-03-05 14:56:01
【问题描述】:
我尝试了很多次将字符串2013-01-27T02:31:47+08:00 转换为NSDate。我找到了苹果的formatting guide 并复制了它的代码并尝试了,但它不起作用。
NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[rfc3339DateFormatter setLocale:enUSPOSIXLocale];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];
// Convert the RFC 3339 date time string to an NSDate.
NSDate *date = [rfc3339DateFormatter dateFromString:@"2013-01-27T02:31:47+08:00"];
【问题讨论】:
标签: ios objective-c ios6 nsdate nsdateformatter