0

我正在尝试为此日期编写 NSDateFormatter 格式。我需要使用什么格式将此字符串解析为 NSDate?

2007-07-01T00:00:00-04:00

4

1 回答 1

1

这是 RFC 3339 日期。在 Apple 文档中有一个解析这种格式的示例:https ://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html

rfc3339DateFormatter = [[[NSDateFormatter alloc] init] autorelease];
enUSPOSIXLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
[rfc3339DateFormatter setLocale:enUSPOSIXLocale];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
date = [rfc3339DateFormatter dateFromString:rfc3339DateTimeString];
于 2012-04-05T16:10:43.107 回答