Golang time.Location type and LoadLocation() function example
package time
Golang time.Location type and LoadLocation() function usage example.
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println("Now: ", now)
fmt.Println(now.Format("Mon, Jan 2, 2006 at 3:04pm"))
fmt.Println("Location: ", now.Location())
// get the time zone name
z, _ := now.Zone()
fmt.Println("Location(Time Zone): ", z)
// load different time zone
est, err := time.LoadLocation("EST") //<---------------------- here !
if err != nil {
fmt.Println(err)
}
fmt.Println("Load Location : ", est)
dayInEST := time.Date(2015, 18, 5, 12, 15, 0, 0, est)
fmt.Println("This code is created on : ", dayInEST.Format("Monday"))
}
Output :
Now: 2009-11-10 23:00:00 +0000 UTC
Tue, Nov 10, 2009 at 11:00pm
Location: UTC
Location(Time Zone): UTC
Load Location : EST
This code is created on : Sunday
References :
Advertisement
Something interesting
Tutorials
+9.6k Golang : Accessing content anonymously with Tor
+6.1k Golang : Function as an argument type example
+5.2k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+6.8k Golang : Calculate pivot points for a cross
+8.6k Golang : How to check variable or object type during runtime?
+25.3k Golang : Storing cookies in http.CookieJar example
+13.4k Golang : Linear algebra and matrix calculation example
+5.5k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+8.8k Golang : Heap sort example
+11.6k CodeIgniter : Import Linkedin data
+8.9k Golang : Sort lines of text example
+15.2k Golang : How to add color to string?