iOS 6 dateFromString返回错误的日期 [英] iOS 6 dateFromString returns wrong date
本文介绍了iOS 6 dateFromString返回错误的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近升级到iOS 6,并且注意到dateFromString无法正常工作,除非我对dateFormat做错了.它在升级之前就可以正常工作.
I recently upgraded to iOS 6 and have noticed dateFromString is not working correctly, unless I'm doing something wrong with my dateFormat. It was working prior to the upgrade.
代码:
NSString *string = @"2012-09-24 - Sun";
NSLog(@"string = %@", string);
NSDateFormatter *df = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
[df setLocale:locale];
[df setDateFormat:@"yyyy-MM-dd - EEE"];
NSDate *date = [df dateFromString:string];
NSLog(@"date = %@", date);
输出:
string = 2012-09-24 - Sun
date = 1999-12-26 05:00:00 +0000
有什么建议吗?
推荐答案
看起来格式化程序更改了iOS 6中的规范:
Looks like the formatters changed specs in iOS 6:
- Formatters in OS X v10.8 and iOS 6.0 use version tr35-25.
- Formatters in iOS 5.0-5.1 use version tr35-19.
这篇关于iOS 6 dateFromString返回错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文