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 :

http://golang.org/pkg/time/#FixedZone

Advertisement