2014 年 12 月 31 日的日期错误。示例代码:
NSDateFormatter *dateF =[[NSDateFormatter alloc] init];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[dateF setLocale:enUSPOSIXLocale];
[dateF setDateFormat:@"MM/DD/yyyy"];
NSDate *date = [dateF dateFromString:@"12/31/2014"];
NSLog(@"Date for locale %@: %@",
[[dateF locale] localeIdentifier], [dateF stringFromDate:date]);
date = [dateF dateFromString:@"01/01/2013"];
NSLog(@"Date for locale %@: %@",
[[dateF locale] localeIdentifier], [dateF stringFromDate:date]);
返回的结果是:
Date for locale en_US_POSIX: 12/335/2014
Date for locale en_US_POSIX: 01/01/2013
这带来了许多问题。1) 我如何获得正确的日期?2)一个月怎么会有335天?
谢谢大家,