猿问

在 GoLang 中使用 GMT+2 获取当前时间

我需要以 Go 语言获取 GMT+2(意大利罗马)的实际时间。

我使用过:time.Now(),但它返回 GMT+0 中的实际日期。

我已经看到有一个 In(loc *Location) 函数,但我不明白如何使用它。还有,你知道如果设置GMT+2,它也会自动考虑DST选项吗?

你可以帮帮我吗?谢谢


守候你守候我
浏览 373回答 1
1回答

DIEA

您可以使用该功能FixedZone或LoadLocation获取 a*Location 然后使用*Location它func In// get the locationlocation,_ := time.LoadLocation("Europe/Rome")// this should give you time in locationt := time.Now().In(location)fmt.Println(t)这是更多文档https://golang.org/pkg/time/#Time
随时随地看视频慕课网APP

相关分类

Go
我要回答