iOS 6 dateFromString返回错误的日期

use*_*234 2 ios6

我最近升级到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)

有什么建议?

Boi*_*ill 6

看起来格式化程序在iOS 6中更改了规格:

  • OS X v10.8和iOS 6.0中的格式化程序使用版本tr35-25.
  • iOS 5.0-5.1中的格式化程序使用版本tr35-19.