尝试在 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/