ios - 在 Swift 中获取类似缩写的时区名称

标签 ios swift timezone

我不明白,突然之间,下面的代码开始给出时区缩写名称而不是时区实际名称。

let timezone = TimeZone.current.identifier

结果: GMT

期待亚洲/加尔各答

Playground output

感谢任何帮助。

最佳答案

注意:GMT 不代表亚洲/加尔各答的时区。 (它应该给你 IST)你应该检查你的设备/模拟器时区设置。如果您正在测试模拟器,请检查您的 (mac) 系统时区。

您的快照表明 - 您正在尝试使用 Playground 编辑器。 尝试为您的 Mac 系统设置位置/时区。

Mac System ► (Go to) System Preference ► Date Time ► Time Zone (Here you can see your system time zone)

enter image description here

enter image description here

我在 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/

相关文章:

ios - 删除应用程序中所有按钮的 UIButton 突出显示

swift - startMonitoringSignificantLocationChanges() 在物理设备上不起作用

javascript - UTC 时间的时刻 Js

php - symfony 中的时区

ios - 在 TableView 导航 Controller 之前添加 swift View Controller 的推荐结构

ios - 从 UITextField 更改后如何更改 UIStepper 值?

ios - 带有按钮特征的 UIAccessibilityElement 在画外音说出按钮后添加 "one of one"

ios - View 被切断(横向与纵向)

ios - Xcode 6.1 消失的 UI 元素

python - Django DateTimeField 说 'You are 5.5 hours ahead of server time.'