ParseInLocation 方法在某些年份产生不正确的结果

Jia*_*ing 1 time timezone go timezone-offset

func main() {
    timeStr := "1974-05-10 10:30:00"
    timeStr2 := "1975-11-10 10:30:00"

    timeZone := "Asia/Ho_Chi_Minh"

    location, err := time.LoadLocation(timeZone)
    if err != nil {
        fmt.Println("Load Location error :", err)
        return
    }

    parsedTime1, err := time.ParseInLocation("2006-01-02 15:04:05", timeStr, location)
    if err != nil {
        fmt.Println("Format error:", err)
        return
    }

    parsedTime2, err2 := time.ParseInLocation("2006-01-02 15:04:05", timeStr2, location)
    if err2 != nil {
        fmt.Println("Format error:", err)
        return
    }

    fmt.Println("parsed time 1:", parsedTime1)
    fmt.Println("parsed time 2:", parsedTime2)

}
Run Code Online (Sandbox Code Playgroud)

游乐场链接:https://go.dev/play/p/RV7hXchRcNx

输出:

parsed time 1: 1974-05-10 10:30:00 +0800 +08
parsed time 2: 1975-11-10 10:30:00 +0700 +07
Run Code Online (Sandbox Code Playgroud)

Goand 中的输出:在此处输入图像描述

对于 1975 年之后的处决,时区是正确的。

您可以查看上面的屏幕截图。

icz*_*cza 5

胡志明市位于越南南部。引用维基百科:越南时间

\n
\n

历史

\n
    \n
  • ...
  • \n
  • 南越时区从1959年12月31日23:00起更改为UTC+08:00,经过了60分钟。
  • \n
  • ...
  • \n
  • 1975 年 4 月\xe2\x80\x93 西贡陷落后,统一的越南于 1975 年 6 月 13 日遵守 UTC+07:00,西贡(和其他南部地区)推迟 60 分钟。
  • \n
\n
\n

因此,在 1959 年 12 月 31 日至 1975 年 5 月之间,南越存在 +08:00 偏移,自 1975 年 6 月 13 日起,存在 +07:00。您的输出是正确的,它考虑了历史变化。

\n