gpt4 book ai didi

ios - iOS 7 中的 NSDateFormatter 字符串

转载 作者:可可西里 更新时间:2023-11-01 05:35:59 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com