开发者

NSDateFormatter has different results when iPad has a 24-hour format

开发者 https://www.devze.com 2023-02-05 15:21 出处:网络
I\'ve been pondering on why this happens for a while now, and I\'ve got no clue. If you run the following code:

I've been pondering on why this happens for a while now, and I've got no clue. If you run the following code:

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);

If the user has configured a 24-hour clock the above prints date is: 2011-01-18 11:00:00 +0000, today is 2011-01-19 00:56:56 +0000. However, when the user selects a 12-hour clock, the above prints date is: (null), today is 2011-01-19 12:58:5开发者_如何转开发1 a.m. +0000.

What I'm I doing wrong? Isn't formatter suppososed to be independent of the locale? please help!

0

精彩评论

暂无评论...
验证码 换一张
取 消