在GoLang获取GMT + 2的当前时间

Rob*_*ani 1 time datetime date go

我需要用Go语言获得GMT + 2(罗马,意大利)的实际时间.

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

我已经看到有一个In(loc*Location)函数,但我无法理解如何使用它.而且,你知道如果设置GMT + 2,它还会自动考虑DST选项吗?

你可以帮帮我吗?谢谢

Vas*_*sif 9

您可以用户功能FixedZoneLoadLocation获得*Location ,然后使用*Locationfunc In

// get the location
location,_ := time.LoadLocation("Europe/Rome")

// this should give you time in location
t := time.Now().In(location)

fmt.Println(t)
Run Code Online (Sandbox Code Playgroud)

这里有更多文档https://golang.org/pkg/time/#Time