NSDateFormatterstring在iOS 7中

尝试在iOS 7中格式化一个date,并在一周中得到一些意想不到的结果。 苹果的文档没有列出iOS 7的模式,但为iOS 6提供的模式在这里 。 看一周的一节

星期几 – 在短短的一天中使用一到三个字母,或者四个用于全名,或者五个用于窄名。

不过,我无法得到4个字母的全名格式化string工作。

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"EEE"]; NSLog(@"%@", [formatter stringFromDate:date]); 

打印“Wed”

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"EEEE"]; NSLog(@"%@", [formatter stringFromDate:date]); 

也打印“星期三”,应该打印“星期三”

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"EEEEE"]; NSLog(@"%@", [formatter stringFromDate:date]); 

打印“W”

是否有一组新的格式化string应该用于iOS 7或我做了什么不正确的?

正如其他人已经注意到,它看起来像一个语言环境问题。

尝试强制如下所示的已知区域设置

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; // or NSLocale *locale = [NSLocale currentLocale]; [formatter setLocale:locale]; [formatter setDateFormat:@"EEEE"]; NSLog(@"%@", [formatter stringFromDate:date]); 

有一个新的Unicode标准 (2013年9月18日发布),但不会改变EEEE格式。

我猜这是依赖于语言环境的。 iOS可能会尝试变得聪明,缩短名称,因为它更符合默认语言环境。 尝试添加一些不同的NSLocale到格式化程序并描述你的结果。