致电Time.In时缺少位置 [英] missing Location in call to Time.In

查看:213
本文介绍了致电Time.In时缺少位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用beego / orm操作Postgresql数据库时,会出现诸如在调用Time.In时缺少位置之类的错误。

When I ues beego/orm to operate postgresql database,there is an error like this "missing Location in call to Time.In".

代码示例

type dataTest struct {
    Id      int         `pk:"auto"`
    Data    time.Time   `orm:"auto_now;type(timestamp);null"`
}

local, _ := time.LoadLocation("UTC")
test_time, err := time.ParseInLocation("2006-01-02 15:04:05", "1111-01-25 14:27:07", local)
orm.DefaultTimeLoc = time.UTC

o,err := orm.NewOrmWithDB("postgres","default",db)
temp := new(dataTest)
temp.Id = 1
temp.Data = test_time
o.Update(temp)


推荐答案

对于docker(构建多阶段)

For docker (build multi stage)

在构建后安装 tzdata

RUN apk --no-cache add tzdata

可用时区列表,请参见: https://golang.org/src/time/zoneinfo_abbrs_windows.go

List of time zones available, see: https://golang.org/src/time/zoneinfo_abbrs_windows.go

loc, _ := time.LoadLocation("America/Bogota")
now := time.Now().In(loc)

这篇关于致电Time.In时缺少位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆