我正在嘗試在 Go 中使用 Time 包來提取時間詳細資訊,如下所示。我已經能夠成功決議諸如年、月、日期、小時、分鐘和秒之類的值。不幸的是,當我嘗試使用 Zone 提取偏移量時,我似乎得到了不正確的偏移量。
當我嘗試查看我的 Time 物件時,我看到兩個偏移條目,不確定我做錯了什么。
serverTime := "2021-10-31T22:17:03.996-0700"
fmt.Println("Server time is: ", serverTime)
t, _ := time.Parse("2006-01-02T15:04:05.999-0700", serverTime)
zone, offset := t.Zone()
fmt.Println("Printing time object: ",t)
fmt.Println("Year", t.Year())
fmt.Println("Month", t.Month().String())
fmt.Println("Date", t.Day())
fmt.Println("Hour", t.Hour())
fmt.Println("Minutes", t.Minute())
fmt.Println("Seconds",t.Second())
fmt.Println("Zone:", zone)
fmt.Println("Offset", offset)
偏移量的輸出是:偏移量 -25200,我希望它是 -0700
這是游樂場的鏈接
uj5u.com熱心網友回復:
該FUNC(時間)區回傳第二個引數offset是UTC以東的秒。所以你的偏移量-0700回傳為-25200- (7 * 60 * 60)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/343532.html
