Golang time.FixedZone() function example
package time
Golang time.FixedZone() function usage example.
package main
import (
"fmt"
"time"
)
func main() {
gmt := time.FixedZone("GMT", 0) // anchor to one zone
fmt.Println("Location: ", gmt)
dayInGMT := time.Date(2015, 18, 5, 12, 15, 0, 0, gmt)
fmt.Println(dayInGMT)
fmt.Println(time.Unix(1258325776, 0).In(gmt), " here and compare below ")
// ----------------------------------------
pst := time.FixedZone("PST", -8*60*60)
fmt.Println("Location: ", pst)
dayInPST := time.Date(2015, 18, 5, 12, 15, 0, 0, pst)
fmt.Println(dayInPST)
fmt.Println(time.Unix(1258325776, 0).In(pst), " see the diff with ^^ ? ")
}
Output :
Location: GMT
2016-06-05 12:15:00 +0000 GMT
2009-11-15 22:56:16 +0000 GMT here and compare below
Location: PST
2016-06-05 12:15:00 -0800 PST
2009-11-15 14:56:16 -0800 PST see the diff with ^^ ?
Reference :
Advertisement
Something interesting
Tutorials
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example
+5.9k AWS S3 : Prevent Hotlinking policy
+9.7k Golang : List available AWS regions
+11.3k Golang : Intercept and process UNIX signals example
+17.9k Golang : Simple client server example
+16.5k Golang : Get IP addresses of a domain name
+23.9k Golang : Call function from another package
+5.6k Golang : Frobnicate or tweaking a string example
+10k Golang : Get escape characters \u form from unicode characters
+8.7k Golang : Combine slices but preserve order example
+11.6k Golang : Concurrency and goroutine example
+9k Golang : Capture text return from exec function example