douqiao5543 2018-01-25 09:20
浏览 103

致电Time.In时缺少位置

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条回答 默认 最新

  • dpzr52746 2018-01-25 14:07
    关注

    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)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示