我遇到了一个陌生的问题。NSDateFormatter 无法解析1988-04-10
为 iOS 6 中的 NSDate 实例。但它适用于 iOS 4 和 iOS 5。这是一个错误吗?
以下是代码。这很简单。
NSArray *values = @[@"1988-04-09", @"1988-04-10", @"1988-04-11"];
NSDateFormatter* df = [[NSDateFormatter alloc] init];
NSLocale *posixLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[df setLocale:posixLocale];
[df setDateFormat:@"yyyy'-'MM'-'dd"];
NSLog(@"timeZone:%@, locale:%@", df.timeZone, df.locale.localeIdentifier);
NSDate* date = nil;
for (NSString *value in values) {
date = [df dateFromString:value];
NSLog(@"The date is %@", date);
}
[posixLocale release];
[df release];
以下是 iOS 4 和 iOS 5 中的结果。
2013-03-19 09:55:32.249 SampleProject[1844:f803] timeZone:Asia/Shanghai (CST (China)) offset 28800, locale:en_US_POSIX
2013-03-19 09:55:32.250 SampleProject[1844:f803] The date is 1988-04-08 16:00:00 +0000
2013-03-19 09:55:32.250 SampleProject[1844:f803] The date is 1988-04-09 16:00:00 +0000
2013-03-19 09:55:32.251 SampleProject[1844:f803] The date is 1988-04-10 15:00:00 +0000
以下是 iOS 6 中的结果。
2013-03-19 09:42:40.824 SampleProject[1455:11303] timeZone:Asia/Shanghai (GMT+08:00) offset 28800, locale:en_US_POSIX
2013-03-19 09:42:40.827 SampleProject[1455:11303] The date is 1988-04-08 16:00:00 +0000
2013-03-19 09:42:40.827 SampleProject[1455:11303] The date is (null)
2013-03-19 09:42:40.828 SampleProject[1455:11303] The date is 1988-04-10 15:00:00 +0000
为空1988-04-10
。是一个错误。谁能解释一下?