当在模拟器和真实设备上将 Settings/General/International/Calendar 设置为日语或佛教时,我在 iOS 上看到了 NSDateFormatter 的问题。年份解析不正确
日期格式化程序
static NSDateFormatter *formatter = nil; // cache this the first time through
if (formatter == nil) {
formatter = [NSDateFormatter new];
formatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; // Fix for QC79748 - Michael Marceau
formatter.dateFormat = @"EEE, d MMM yyyy HH:mm:ss zzz";
formatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
formatter.calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
formatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0]] autorelease];
}
NSLog(@"CorrectDate%@",[serviceHeaders safeObjectForKey:@"Date"] );
NSLog(@"Formatted date:%@",[formatter dateFromString:[serviceHeaders safeObjectForKey:@"Date"]]);
Output
Correct - Mon, 27 Aug 2012 16:33:14 GMT
Formatted date:0024-08-27 16:33:14 +0000