Golang time.Time.Zone() function example
package time
Golang time.Time.Zone() function usage example.
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println("Now: ", now)
// reduce the date format
// remember NOT to use 2006-01-01 or 02-02 or same digit
// for month and date. Will cause weird date result
fmt.Println(now.Format("2006-01-02"))
fmt.Println("Location: ", now.Location())
// get the time zone name
z, offset := now.Zone()
fmt.Printf("Location(Time Zone) : %v and offset : %v \n", z, offset)
}
Sample output :
Now: 2015-08-11 17:21:52.776537624 +0800 MYT
2015-08-11
Location: Local
Location(Time Zone) : MYT and offset : 28800
Reference :
See also : Golang time.Location type and LoadLocation() function example
Advertisement
Something interesting
Tutorials
+21.4k Golang : How to get time zone and load different time zone?
+5.7k PHP : Fix Call to undefined function curl_init() error
+8.4k Golang : Get final or effective URL with Request.URL example
+6.2k Golang : Measure execution time for a function
+16k Golang : Update database with GORM example
+51.5k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+15.7k Golang : How to convert(cast) IP address to string?
+5.9k Golang : List all packages and search for certain package
+9.6k Golang : Changing a RGBA image number of channels with OpenCV
+40.3k Golang : UDP client server read write example
+19.4k Golang : Populate dropdown with html/template example
+27k Golang : Find files by extension