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