我不明白,突然之间,下面的代码开始给出时区缩写名称而不是时区实际名称。
let timezone = TimeZone.current.identifier
结果: GMT
期待亚洲/加尔各答
感谢任何帮助。
最佳答案
注意:GMT 不代表亚洲/加尔各答的时区。 (它应该给你 IST)你应该检查你的设备/模拟器时区设置。如果您正在测试模拟器,请检查您的 (mac) 系统时区。
您的快照表明 - 您正在尝试使用 Playground 编辑器。 尝试为您的 Mac 系统设置位置/时区。
Mac System ► (Go to) System Preference ► Date Time ► Time Zone (Here you can see your system time zone)
我在 IST/India 的给定结果中尝试了以下代码:
print("**> TimeZone.current.identifier - \(TimeZone.current.identifier)\n")
// TimeZone.current.identifier - Asia/Kolkata
print("**> TimeZone.current.description - \(TimeZone.current.description)\n")
// TimeZone.current.description - Asia/Kolkata (current)
print("**> TimeZone.current.debugDescription - \(TimeZone.current.debugDescription)\n")
// TimeZone.current.debugDescription - Asia/Kolkata (current)
关于ios - 在 Swift 中获取类似缩写的时区名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47219110/