日期格式化程序在iOS6中不工作,但在ios7中工作得很好
以以下格式处理日期字符串:日期格式化程序在iOS6中不工作,但在ios7中工作得很好,ios,objective-c,nsdateformatter,Ios,Objective C,Nsdateformatter,以以下格式处理日期字符串:2014年6月12日-19:35:51 UTC NSString * dateStr = @"June 12, 2014 - 19:35:51 UTC"; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; [dateFormatter setDateForma
2014年6月12日-19:35:51 UTC
NSString * dateStr = @"June 12, 2014 - 19:35:51 UTC";
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"MMMM dd, yyyy - HH:mm:ss Z"];
NSDate *startTime = [dateFormatter dateFromString: dateStr];
这在iOS7中非常有效,而不是在iOS6中。请尝试如下设置区域设置:
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];