iphone-NSDateFormatter问题?
我有一个格式化程序iphone-NSDateFormatter问题?,iphone,objective-c,nsdateformatter,Iphone,Objective C,Nsdateformatter,我有一个格式化程序 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; 对于值:2010-01-01 05:00:00.000 它返回正确的值 但对于值:2010-01-01 05:22:00.000 它返回null 根据文档,如果我在分钟内是正确的,我将使用“mm” 那么,我的代码有什么问题,为什么它返回nil NSDateFormatter * f = [[NSDateFormatter alloc] init]; [f se
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
对于值:2010-01-01 05:00:00.000
它返回正确的值
但对于值:2010-01-01 05:22:00.000
它返回null
根据文档,如果我在分钟内是正确的,我将使用“mm”
那么,我的代码有什么问题,为什么它返回nil
NSDateFormatter * f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
NSLog(@"%@", [f dateFromString:@"2010-01-01 05:00:00.000"]);
NSLog(@"%@", [f dateFromString:@"2010-01-01 05:22:00.000"]);
[f release];
日志:
因此,它正确地解析事物。因此,你在别的地方做错了什么
日志:
因此,它正确地解析事物。因此,你在别的地方做错了什么事。我觉得很清楚。我试了一下,得到了正确的结果:
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
NSDate *date = [f dateFromString:@"2010-01-02 03:44:55.666"];
NSLog(@"%@",date);
NSDateFormatter *f2 = [[NSDateFormatter alloc] init];
[f2 setDateFormat:@"d. MMMM yyyy HH mm ss SSS"];
NSString *s = [f2 stringFromDate:date];
NSLog(@"Date is really %@",s);
返回了以下输出:
2010-11-16 18:48:35.221 Test3[6407:207] 2010-01-02 03:44:55 -0500
2010-11-16 18:48:35.223 Test3[6407:207] Date is really 2. January 2010 03 44 55 666
我觉得很干净。我试了一下,得到了正确的结果:
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
NSDate *date = [f dateFromString:@"2010-01-02 03:44:55.666"];
NSLog(@"%@",date);
NSDateFormatter *f2 = [[NSDateFormatter alloc] init];
[f2 setDateFormat:@"d. MMMM yyyy HH mm ss SSS"];
NSString *s = [f2 stringFromDate:date];
NSLog(@"Date is really %@",s);
返回了以下输出:
2010-11-16 18:48:35.221 Test3[6407:207] 2010-01-02 03:44:55 -0500
2010-11-16 18:48:35.223 Test3[6407:207] Date is really 2. January 2010 03 44 55 666