dou7851 2018-10-01 21:34
浏览 181

从SQLite获取DATETIME

Using orm (GORM) for GoLang (1.11), DB is SQLite (imported from MySQL as it is) and I have a problem with datetime conversion

import (
    ...
    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/sqlite"
    "time"
)

type Product struct {
    P_id           int        `json:"p_id"`
    Z_id           int        `json:"z_id"`
    Name           string     `json:"name"`
    ...
    Pushed         int        `json:"pushed"`
    Cn_color       int        `json:"cn_color"`
    Updated_at     time.Time  `json:"updated_at"`
}

func GetProduct() {

    db, err = gorm.Open("sqlite3", "./data/godb.db")

    if err != nil {
        panic("Could not connect to DB")
    }

    defer db.Close()

    var product Product

    db.Where("p_id = ?", c.Param("p_id")).First(&product)

    fmt.Print(product.Updated_at)
}

And i recieved

0001-01-01 00:00:00 +0000 UTC

But in DB i have

2018-02-28 14:17:56

How can I specify the type of datetime field?

I've tried:

but nothing happens

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料