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
+11.5k Golang : Change date format to yyyy-mm-dd
+4.7k JavaScript: Add marker function on Google Map
+6.8k Golang : Join lines with certain suffix symbol example
+6k Linux/MacOSX : Search for files by filename and extension with find command
+6.1k Golang : How to write backslash in string?
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+16.5k Golang : Check if a string contains multiple sub-strings in []string?
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+11.3k Golang : Post data with url.Values{}