此代码适用于我可以确定的所有区域/区域设置组合,除非我将手机设置为12小时时钟设置的英国区域。有人能告诉我为什么吗?
这适用于每个地区,包括设置了12小时时钟的英国:
NSDateFormatter *theDateFormatter = [[NSDateFormatter alloc] init];
theDateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ";
NSString *theLastFetchDateString = @"2015-11-13T01:47:52.4630000Z";
NSDate *theLastFetchDate = [theDateFormatter dateFromString:theLastFetchDateString];这在除英国以外的所有地区都有效,并设置了12小时时钟:
NSDateFormatter *theDateFormatter = [[NSDateFormatter alloc] init];
theDateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ";
NSString *theLastFetchDateString = @"2015-11-13T18:14:44.1230000Z";
NSDate *theLastFetchDate = [theDateFormatter dateFromString:theLastFetchDateString];我看到的主要区别是第二个日期是以24小时格式存储的,而解析设备是以12小时格式存储的,但是格式化程序HH应该能够处理它,对吧?
或者“下午”。其中美国12小时时钟将它们格式化为“AM”或“PM”。
发布于 2015-12-09 02:55:29
您正在分析RFC 3339/ISO 8601日期。因此,您应该将格式化程序的locale设置为en_US_POSIX。
theDateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];https://stackoverflow.com/questions/34163266
复制相似问题