[Go] Get the name of a time zone

Created on November 30, 2026

Call Location() on a time.Time value to get its *time.Location. Call String() on the location to get its name.

package main

import (
    "fmt"
    "time"
)

func main() {
    location, err := time.LoadLocation("Asia/Tokyo")
    if err != nil {
        fmt.Printf("%#v", err)
    }
    t := time.Now().In(location)
    fmt.Print(t.Location().String())
}

Output

Asia/Tokyo
Go