我有以下操場代碼:
let dateFormatter = ISO8601DateFormatter()
let zurichTimeZone = TimeZone(identifier: "Europe/Zurich")
dateFormatter.timeZone = zurichTimeZone
// dateFormatter.timeZone = .init(abbreviation: "GMT 1:00")
// prints timezone 1
print(dateFormatter.string(from: Date(timeIntervalSince1970: TimeInterval(100400))))
// prints timezone 2
print(dateFormatter.string(from: Date(timeIntervalSince1970: TimeInterval(1665957700))))
第一個輸出是"1970-01-02T04:53:20 01:00",第二個輸出是"2022-10-17T00:01:40 02:00"。為什么 GMT 值會發生變化?如果使用“Europe/Kalingrad”作為識別符號,我將從第一次列印中獲得 3 ,從第二次列印中獲得 2 。當我使用"dateFormatter.timeZone = .init(abbreviation: "GMT 1:00")"設定時區時,問題不會出現。當我使用"Pacific/Guam"時,我也找不到這種行為。
uj5u.com熱心網友回復:
命名TimeZone
的 s 考慮夏令時 (DST),而由 GMT 偏移創建的則不考慮。
蘇黎世冬令時為 GMT 1,夏令時為 GMT 2。
您創建的 2 個日期位于時鐘變化的不同側,因此 1 個使用夏令時,而另一個使用冬令時。這就是使用 2 個不同時區的 1 小時時差的來源。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/526039.html
標籤:迅速时区