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 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?