missing Location in call to Time.In

[亡魂溺海] 提交于 2020-06-16 03:49:28

问题


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

code example

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)

回答1:


This should work:

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)



回答2:


For docker (build multi stage)

Install tzdata after build

RUN apk --no-cache add tzdata

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)


来源:https://stackoverflow.com/questions/48439363/missing-location-in-call-to-time-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!