我需要以 Go 语言获取 GMT+2(意大利罗马)的实际时间。我使用过:time.Now(),但它返回 GMT+0 中的实际日期。我已经看到有一个 In(loc *Location) 函数,但我不明白如何使用它。还有,你知道如果设置GMT+2,它也会自动考虑DST选项吗?你可以帮帮我吗?谢谢
1 回答

DIEA
TA贡献1820条经验 获得超3个赞
您可以使用该功能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 关注
- 372 浏览
添加回答
举报
0/150
提交
取消