我一直在思考为什么这种情况发生了一段时间,我一点也不清楚。如果您运行以下代码:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MM-yyyy|HH:mm"];
NSDate *date = [formatter dateFromString:@"18-01-2011|06:00"];
NSDate *today = [[NSDate alloc] init];
NSLog(@"date is: %@, today is %@", date, today);
如果用户配置了24小时制,则上面打印date is: 2011-01-18 11:00:00 +0000, today is 2011-01-19 00:56:56 +0000
。但是,当用户选择12小时制时,上面会打印date is: (null), today is 2011-01-19 12:58:51 a.m. +0000
。
我做错了什么?是不是formatter
被假定独立于语言环境?请帮忙!