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 to read/write from/to file in Golang?
Select single argument from all arguments of variadic function
Regular expression to extract numbers from a string in Golang
Example: Split, Join, and Equal from BYTES Package
Sierpinski triangle in Go Programming Language
Replace numbers by zero from string