Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS系统区域设置标识符为空_Ios_Swift_Nsdate_Nsdateformatter - Fatal编程技术网

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

iOS系统区域设置标识符为空,ios,swift,nsdate,nsdateformatter,Ios,Swift,Nsdate,Nsdateformatter,我在使用日期格式化程序时注意到一些奇怪的事情。下面是日期格式化程序的代码 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”。这有点奇怪。但是,删除格式化程序的区域设置会得到

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

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()

在苹果的API文档中已经有一个观点

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

供参考: