我們不能使用 Zone() 返回的偏移量:package mainimport "fmt"import "time"func main() { loc, _ := time.LoadLocation("America/Los_Angeles") t := time.Date(2015,04,12,19,23,0,0,loc) t2 := time.Date(2015,03,1,19,23,0,0,loc) _, offset := t.Zone() _, offset2 := t.Zone() fmt.Printf("t1: %v offset: %d\n", t, offset) fmt.Printf("t2: %v offset: %d\n", t2, offset2)}這將返回:t1: 2015-04-12 19:23:00 -0700 PDT offset: -25200t2: 2015-03-01 19:23:00 -0800 PST offset: -25200偏移量不反映夏令時(shí)。格式化時(shí)間實(shí)例后手動(dòng)解析偏移量是唯一的選項(xiàng)(-0700 和 -0800)嗎?我們可以使用 time.Now() 檢索當(dāng)前時(shí)間,但使用 .In() 只是更改位置而不調(diào)整小時(shí)和分鐘。
- 1 回答
- 0 關(guān)注
- 231 瀏覽
添加回答
舉報(bào)
0/150
提交
取消