【问题标题】:Getting timezone name like abbreviation in Swift在 Swift 中获取时区名称,如缩写
【发布时间】:2017-11-10 09:05:30
【问题描述】:

我不明白,这一切都很突然,下面的代码开始给出时区缩写名称而不是时区实际名称。

let timezone = TimeZone.current.identifier

结果:格林威治标准时间

预期:亚洲/加尔各答

感谢任何帮助。

【问题讨论】:

  • 对我来说,它可以正常工作。 (亚洲/加尔各答)。您是否更新/更改了设备中的任何内容/设置?
  • 这是因为您的 当前时区GMT 而不是 Asia/Kolkata。如果您当前的时区为Asia/Kolkata,则标识符为Asia/Kolkata
  • 不,AFAIK 亚洲/加尔各答属于格林威治标准时间。但不是这两个是分开的。如果我错了,请纠正我
  • GMT 代表Greenwich Mean Time,其中GreenwichLondon, UK 附近的位置。它离Kolkata 很远。我的意思是:检查你的时区设置,它们是无效的。

标签: ios swift timezone


【解决方案1】:

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

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

Mac 系统 ►(转到)系统偏好 ► 日期时间 ► 时区(在这里您可以看到您的系统时区)

我尝试了以下代码,给出了 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    • 2013-08-17
    • 2016-09-03
    • 2013-11-26
    相关资源
    最近更新 更多