Reputation: 790
I need to get the actual time in GMT+2 (Rome, Italy) in Go language.
I've used: time.Now() but it returns the actual date in GMT+0.
I've seen that there's a In(loc *Location) function but I can't understand how to use it. And also, do you know if setting GMT+2, it also consider the DST option in automatic?
Could you help me? Thanks
Upvotes: 3
Views: 11898
Reputation: 849
According to @Vasif, this is the code which use time.FixedZone
function
// the offset is second
var yourLocation = time.FixedZone("GMT+2", 2*60*60)
here is the doc https://pkg.go.dev/time#FixedZone
Upvotes: 0
Reputation: 1413
You can user the function FixedZone
or LoadLocation
to get a *Location
And then use that *Location
in 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)
Here is more of docs https://golang.org/pkg/time/#Time
Upvotes: 12