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
+4.8k Linux : Disable and enable IPv4 forwarding
+19.9k Golang : How to get time zone and load different time zone?
+10.7k Golang : Split strings into command line arguments
+12.3k Golang : Verify token from Google Authenticator App
+18.2k Golang : Compare floating-point numbers
+5.3k Golang : Extract sub-strings
+4.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+16.2k Golang : Parse date string and convert to dd-mm-yyyy format
+12.6k Golang : unknown escape sequence error
+13.1k Golang : How to get URL port?
+19k Golang : Secure(TLS) connection between server and client
+30.1k Golang : Math pow(the power of x^y) example