5
下面是代码:IOS 6和NSDateFormatter
NSString * str = @"2012-11-23Fri09:00:00+0100";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSLocale *locale= [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatter setLocale:locale];
[formatter setDateFormat:@"yyyy-MM-ddEEEHH:mm:ssZ"];
NSDate *result = [formatter dateFromString:str];
NSLog(@"str :%@ -- NSDate :%@", str, result);
这里是输出:
str :2012-11-23Fri09:00:00+0100 -- NSDate :1999-12-31 08:00:00 +0000
为什么NSDate
是错误的?
我试图在iPhone上你的代码5.0模拟器和工作正常,上iPhone 6.0模拟器失败。这可能是一个错误,你必须发送你的代码在苹果开发者论坛 –
这绝对是一个与iOS 6的错误。如果我们从那里删除“星期五”和“EEE”,它工作正常。日期名称出现在日期中间时出现一些错误。 – iDev