Golang Get current Date and Time in EST, UTC and MST?
Example
package main
import (
"fmt"
"time"
)
func main() {
t := time.Now()
z, _ := t.Zone()
fmt.Println("ZONE : ", z, " Time : ", t) // local time
location, err := time.LoadLocation("EST")
if err != nil {
fmt.Println(err)
}
fmt.Println("ZONE : ", location, " Time : ", t.In(location)) // EST
loc, _ := time.LoadLocation("UTC")
now := time.Now().In(loc)
fmt.Println("ZONE : ", loc, " Time : ", now) // UTC
loc, _ = time.LoadLocation("MST")
now = time.Now().In(loc)
fmt.Println("ZONE : ", loc, " Time : ", now) // MST
}
Output
ZONE : IST Time : 2017-08-26 22:12:31.3763932 +0530 IST
ZONE : EST Time : 2017-08-26 11:42:31.3763932 -0500 EST
ZONE : UTC Time : 2017-08-26 16:42:31.3773933 +0000 UTC
ZONE : MST Time : 2017-08-26 09:42:31.3783934 -0700 MST
Most Helpful This Week
How can we reverse a simple string in Go?
Dynamic JSON parser without Struct in Golang
Copy an array by value and reference into another array
How to read/write from/to file in Golang?
Find capacity of Channel, Pointer and Slice
How to set timeout for http.Get() requests in Golang?
How to find length of Map in Go?
How to check lowercase characters in a string in Golang?
Golang Slice vs Map Benchmark Testing
How to import and alias package names?