简体   繁体   English

在Swift中获取时区名称(如缩写)

[英]Getting timezone name like abbreviation in Swift

I don't understand, all of it's sudden, below code started giving timezone abbreviation name instead of timezone actual name. 我不明白,这很突然,下面的代码开始提供时区缩写名称而不是时区实际名称。

let timezone = TimeZone.current.identifier

Result: GMT 结果: GMT

Expecting: Asia/Kolkata 期待:亚洲/加尔各答

游乐场输出

Any help is appreciated. 任何帮助表示赞赏。

Note: GMT does not represent timezone for Asia/Kolkata. 注意:格林尼治标准时间不代表亚洲/加尔各答的时区。 (It should give you IST) You should check your device/simulator time zone settings. (应该给您IST)。您应该检查设备/模拟器的时区设置。 If you are testing simulator then check your (mac) system time zone. 如果要测试模拟器,请检查(mac)系统时区。

Your snapshot indicates - you are trying with Playground editor. 您的快照表明-您正在尝试使用Playground编辑器。 Try to set location/time zone for your Mac system. 尝试为Mac系统设置位置/时区。

Mac System ► (Go to) System Preference ► Date Time ► Time Zone (Here you can see your system time zone) Mac系统►(转到)系统偏好设置►日期时间►时区(在这里您可以看到系统时区)

在此处输入图片说明

在此处输入图片说明

I tried following code with given results for IST/India: 我尝试使用以下代码为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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM