我需要以 Go 語(yǔ)言獲取 GMT+2(意大利羅馬)的實(shí)際時(shí)間。我使用過(guò):time.Now(),但它返回 GMT+0 中的實(shí)際日期。我已經(jīng)看到有一個(gè) In(loc *Location) 函數(shù),但我不明白如何使用它。還有,你知道如果設(shè)置GMT+2,它也會(huì)自動(dòng)考慮DST選項(xiàng)嗎?你可以幫幫我嗎?謝謝
1 回答

DIEA
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊
您可以使用該功能FixedZone或LoadLocation獲取 a*Location 然后使用*Location它func In
// get the location
location,_ := time.LoadLocation("Europe/Rome")
// this should give you time in location
t := time.Now().In(location)
fmt.Println(t)
這是更多文檔https://golang.org/pkg/time/#Time
- 1 回答
- 0 關(guān)注
- 359 瀏覽
添加回答
舉報(bào)
0/150
提交
取消