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
+38k Golang : Converting a negative number to positive number
+10.6k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+8.6k Golang : How to check variable or object type during runtime?
+4.7k Linux : sudo yum updates not working
+11.3k Golang : How to pipe input data to executing child process?
+20.1k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+18.4k Golang : How to get hour, minute, second from time?
+18.6k Golang : Generate thumbnails from images
+18.8k Golang : Implement getters and setters
+6.4k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+23.2k Golang : simulate tail -f or read last line from log file example
+18.8k Golang : Iterating Elements Over A List