尝试在 golang 1.17.6 中调用 LoadLocation 时出现“未知时区 America/Ciudad_Juarez”

问题描述 投票:0回答:1

我使用 time.LoadLocation(tz) 从不同位置检索时区,它提供所有时间信息以及一些额外的元数据。除了 America/Ciudad_Juarez 之外,一切正常。

这个简单的代码:

import (
    "time"
)

loc, err := time.LoadLocation("America/Ciudad_Juarez")
    if err != nil {
        println(err)
    }

收到错误消息“未知时区 America/Ciudad_Juarez”。 有谁知道如何解决这个问题?

go time
1个回答
0
投票

America/Ciudad_Juarez 是相对较新的时区。

LoadLocation 按给定顺序和位置搜索时区

// LoadLocation looks for the IANA Time Zone database in the following
// locations in order:
//
//   - the directory or uncompressed zip file named by the ZONEINFO environment variable
//   - on a Unix system, the system standard installation location
//   - $GOROOT/lib/time/zoneinfo.zip
//   - the time/tzdata package, if it was imported

您可以从 1.22(撰写本文时)开始下载最新的 Go 版本存储库:https://github.com/golang/go/blob/master/lib/time/zoneinfo.zip

使用新下载的文件下载并更新

$GOROOT/lib/time/zoneinfo.zip

© www.soinside.com 2019 - 2024. All rights reserved.