ios - iOS 7 中的 NSDateFormatter 字符串

标签 ios date ios7

尝试在 iOS 7 中设置日期格式并获得星期几的一些意外结果。 Apple 的文档没有列出适用于 iOS 7 的模式,但为 iOS 6 提供的模式是 here .查看星期部分

Day of week - Use one through three letters for the short day, or four for the full name, or five for the narrow name.

但是我无法使 4 个字母的全名格式化程序字符串起作用。

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

打印“星期三”

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

也打印“Wed”,应该打印“Wednesday”

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

打印“W”

是否有一套新的格式字符串应该用于 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]);

关于ios - iOS 7 中的 NSDateFormatter 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19453436/

相关文章:

ios - 限制地点自动完成的结果 - GOOGLE API AUTO COMPLETE

ios - UISlider 管理 UIPageViewController 分页

ios - 图层边界未显示在 View 和 UITableView 的顶部和右边缘

ios - 无法在 ios 7 中设置 uilabel 字体(不使用自定义字体)

ios - 在 iOS 中获取街道名称

ios - 基于 AutoLayout 的应用程序中的 NSAutoresizingMaskLayoutConstraint 错误

python - 将字符串转换为日期时间python

java - 字符串日期到 SQL 日期添加年份

javascript - Firebase 日期存储出错

iOS 7 TextKit - 如何插入与文本内联的图像?