Standard library / time

time.LoadLocationFromTZData()

Create a location from TZif-format bytes, useful for explicitly supplied zone data. Invalid data returns an error. Expected stdout: 'UTC +0000\n'.

Formal Syntax & Structure

go syntaxgo
func LoadLocationFromTZData(name string, data []byte) (*Location, error)

Parameters & Attributes

NameTypeDescription
namestringLocation name.
data[]byteTZif time-zone file bytes.

Return Value

(*Location, error)

Create a location from TZif-format bytes, useful for explicitly supplied zone data.

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func must(err error) {  if err != nil {    panic(err)  }}func main() {  data := append([]byte("TZif\x00"), make([]byte, 39)...)  data[39] = 1  data[43] = 4  data = append(data, 0, 0, 0, 0, 0, 0, 'U', 'T', 'C', 0)  loc, err := time.LoadLocationFromTZData("Fixture", data)  must(err)  fmt.Println(time.Unix(0, 0).In(loc).Format("MST -0700"))}
Go Reference