当我使用postgresql数据库时,会出现错误,例如“在调用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)
答案 0 :(得分:0)
这应该有效:
type dataTest struct {
Id int `pk:"auto"`
Data time.Time `orm:"auto_now;type(timestamp);null"`
}
test_time, err := time.ParseInLocation("2006-01-02 15:04:05", "1111-01-25 14:27:07", time.UTC)
orm.DefaultTimeLoc = time.UTC
o,err := orm.NewOrmWithDB("postgres","default",db)
temp := new(dataTest)
temp.Id = 1
temp.Data = test_time
o.Update(temp)
答案 1 :(得分:0)
对于Docker(构建多阶段)
在构建后安装 tzdata
RUN apk --no-cache add tzdata
可用时区列表,请参见:https://golang.org/src/time/zoneinfo_abbrs_windows.go
loc, _ := time.LoadLocation("America/Bogota")
now := time.Now().In(loc)