NSString *string = @"1990-04-15";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
return [dateFormatter dateFromString:string];
这总是返回null,当“string”被任何其他日期字符串更改时,它的功能正常,这个日期(1990-04-15)是如此特别吗?
xcode 5,IOS 7,iphone app
整个方法和背景:
“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);
答案 0 :(得分:4)