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 use array in Go Programming Language?
Create and Print Multi Dimensional Slice in Golang
How To Make an HTTP Server in Golang?
How to Convert string to float type in Go?
Example to use Weekday and YearDay function
Higher Order Functions in Golang
How to use function from another file golang?
How to Draw a rectangle in Golang?
Anonymous Functions in Golang
Generate a Keygen of 256 bits