我正在尝试在 Go 中使用 Time 包来提取时间详细信息,如下所示。我已经能够成功解析年、月、日、小时、分钟和秒等值。不幸的是,当我尝试使用 Zone 来提取偏移量时,我似乎得到了不正确的偏移量。
当我尝试查看我的时间对象时,我看到两个偏移条目,不确定我做错了什么。
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
这是游乐场的链接
长风秋雁
相关分类