gpt4 book ai didi

iOS 系统区域设置标识符为空

转载 作者:行者123 更新时间:2023-11-30 13:36:23 25 4
gpt4 key购买 nike

我在使用日期格式化程序时注意到一些奇怪的事情。下面是日期格式化程序的代码。

let formatter = NSDateFormatter()
formatter.dateFormat = "EEE dd MMM h:mm a"
formatter.locale = NSLocale.systemLocale()
print(formatter.stringFromDate(NSDate()) )

输出为:“Fri 18 M03 1:05 PM”。这有点奇怪。但是,删除格式化程序的区域设置可以得到我想要的输出:“Fri 18 Mar 1:05 PM”。

我还尝试打印出 NSLocale.systemLocale(),输出是一个空字符串。这正常吗?当您更改区域设置时,日期格式化程序实际上发生了什么?

仅供引用:我正在实际设备上对此进行测试。并且在设备设置中更改区域格式不会影响区域设置标识符。

最佳答案

如果你想使用系统设置,应该使用这个NSLocale.currentLocale()

在 Apple 的 API 文档中已经提到了这一点。

讨论当您不需要任何本地化时,请使用系统区域设置。使用当前区域设置设置向用户显示的文本格式。

仅供引用:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSLocale_Class/index.html#//apple_ref/occ/clm/NSLocale/systemLocale

关于iOS 系统区域设置标识符为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36026198/

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