NSTimeZone returns 来自两个不同时区的相同本地化名称

NSTimeZone returns the same localized name from two different timeZones

我有一个应用程序可以计算两个位置之间的时差,我只是意识到选择 "Europe/London" 和 "GMT" 两者 returns 相同的字符串 "Greenwich Mean Time"

    buttonTimeZone.setTitle(timeZone?.localizedName(for: .standard, locale: locale), for: .normal)
    print("timeZone:\(String(describing: timeZone?.description))") 

按钮显示"Greenwich Mean Time",但我相信GMT和Europe/London有1小时的时差。

我添加了第二行 print,以确保我在测试时选择了两个不同的区域。测试时间为2017年10月28日

感谢您的意见!

我刚刚意识到伦敦在夏令时,因为时钟今天才变回来。我所要做的就是在 DST 时将样式从 .standard 更改为 .daylightsaving。

    var title = timeZone?.localizedName(for: .standard, locale: locale)
    if (timeZone?.isDaylightSavingTime(for: dateTimeComplete!))! {
        title = timeZone?.localizedName(for: .daylightSaving, locale: locale)
    }
    buttonTimeZone.setTitle(title, for: .normal)