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

DIEA
TA貢獻1820條經驗 獲得超2個贊
您可以使用該功能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 關注
- 364 瀏覽
添加回答
舉報
0/150
提交
取消