一个错误? NSDateFormatter dateFromString仅为此date返回null

NSString *string = @"1990-04-15"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; return [dateFormatter dateFromString:string]; 

这总是返回null,当“string”被任何其他datestring改变时,它的function正常,这个date(1990-04-15)如此特别吗?

Xcode 5,IOS 7,iPhone应用程序

整个方法和上下文:

在“Tools.m”中:

 +(NSDate *)stringToDate:(NSString *)string{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; return [dateFormatter dateFromString:string]; } 

和这个方法叫做:

 NSDate *date = [Tools stringToDate:@"1990-04-15"]; NSLog(@"---- the date:%@",date); 

你在中国吗? 如果是这样,那是因为时间转移到了夏令时,所以1990年4月15日午夜不存在 – 时间直接跳到了凌晨1点。 (你没有提供时间,默认时间是午夜,而且你没有提供时区,所以假定你自己的语言环境。)