我最近升级到iOS 6,并注意到dateFromString无法正常工作,除非我的dateFormat做错了.它在升级之前正在工作.
码:
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);
Run Code Online (Sandbox Code Playgroud)
输出:
string = 2012-09-24 - Sun
date = 1999-12-26 05:00:00 +0000
Run Code Online (Sandbox Code Playgroud)
有什么建议?
| 归档时间: |
|
| 查看次数: |
1648 次 |
| 最近记录: |