Windows Server 2022设置时区错误 unknown time zone Asia/Shanghai
qqeip opened this issue · comments
panic: unknown time zone Asia/Shanghai
goroutine 1 [running]:
github.com/xinliangnote/go-gin-api/pkg/timeutil.init.0()
E:/New/go-gin-api/pkg/timeutil/timeutil.go:19 +0x87
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
fmt.Println("Failed to load time zone:", err)
//return
}
time.Local = loc
fmt.Println(time.Local)
casetime := time.Now().Format("2006-01-02 15:04:05.000")
fmt.Println(casetime)
显示time.Local=UTC 显示的时间差8小时
改为Local可以解决
loc, err := time.LoadLocation("Local") //Asia/Shanghai")