iphone - iOS 6 NSDateFormatter stringFromDate : empty day of week

标签 iphone objective-c ios6 nsdateformatter dayofweek

我在获取 iOS 6 NSDate 对象中星期几的全名时遇到问题(在 iOS 7 中工作正常)。 我在 stackoverflow 上搜索了类似的问题,但没有找到我要找的东西。

我的测试用例是:

formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEEE"];
[formatter setDoesRelativeDateFormatting:NO];

NSDate *testDate = [NSDate dateWithTimeIntervalSince1970:1384551041.389218];
NSLog(@"%@",[formatter stringFromDate:testDate]);

预期的输出是 Frid​​ay(本地化为您的设备区域格式和公历),它适用于 iOS 7,但在 iOS 6 上它返回空描述。我已经在具有相同区域格式集的实际设备中进行了测试。

据我所知,iOS 6 使用tr35-25根据 this documentation 格式化, EEEE 以该格式指定全名星期几。

我错过了什么吗?

最佳答案

这实际上看起来像是 iOS 6 上 NSDateFormatter 中的一个错误。然而,看起来 仅当您明确设置时才会出现此错误

[formatter setDoesRelativeDateFormatting:NO];

如果您省略该行(无论如何 NO 都是默认值),那么结果是可以的(至少在我测试时是这样)。

备注:我假设 setDoesRelativeDateFormatting 仅用于连接 使用 setDateStyle:,但这纯属猜测。

关于iphone - iOS 6 NSDateFormatter stringFromDate : empty day of week,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20095742/

相关文章:

ios - Google maps turn by turn 用于 ios 开发的 gps 导航

ios - 将一个 NSString 复制到另一个 Xcode

iphone - UIFont Woes(一些自定义字体加载,但其他的不是)

Objective-C: floorf( ) 返回错误值

ios - CLLocationManager didUpdateToLocation :, 在哪个线程上?

ios5 - 调用应用程序的时间:didFinishLaunchingWithOptions:在iOS 5.x和iOS 6之间有所不同

iphone - 如何使用 Core Data 加快将新对象插入实体的速度

ios - 有什么方法可以检索 iPhone 的显示亮度和光传感器值?

ios - 在 iOS 7 中自定义 UISearchBar

safari - 在 iOS 6 上的 Safari 上授权使用 JS 客户端 API 库时,是否可以支持多个 Google 帐户?