[Go] Parse a date string in a specified time zone

Created on November 30, 2026

Use time.ParseInLocation to interpret a date string without a time zone as local time in a specified location. This example uses Asia/Tokyo.

package main

import (
    "fmt"
    "time"
)

func main() {
    locationAsiaTokyo, err := time.LoadLocation("Asia/Tokyo")
    if err != nil {
        panic("Could not load or parse the time")
    }

    t, err := time.ParseInLocation("2006-01-02 15:04:05", "2022-09-01 00:00:00", locationAsiaTokyo)
    if err != nil {
        panic("Could not load or parse the time")
    }

    fmt.Println(t.Format("2006年01月02日 15時04分05秒"))
}

Output

2022年09月01日 00時00分00秒
Go