这是我的代码:

package main

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


func (Rank) TableName() string {
    return "Score_rank"
}

// Overriding Column Name
type Rank struct {
    Id   int64     `gorm:"column:id"`
    DateCreation    time.Time `gorm:"column:dateCreation`
    Score         time.Time    `gorm:"column:score"`
    Rank         time.Time   `gorm:"column:rank"`
    ReceiverId       int64     `gorm:"column:receiver_id"`
}


func main() {
    db, err := gorm.Open("postgres", "host=127.0.0.1 port=5432 user=toto dbname=repsys password=akaburrules")
    defer db.Close()
    if err != nil {
        panic("failed to connect database")
    }
    defer db.Close()


    var rank Rank
    //db.First(&rank)
    db.First(&rank)
    fmt.Println(rank)
    fmt.Println(rank.ReceiverId)
    fmt.Println(rank.DateCreation)
}

输出是:

{3 0001-01-01 00:00:00 +0000 UTC 2018-06-23 13:34:35 +0200 CEST 2018-06-23 13:34:36 +0200 CEST 3}
3
0001-01-01 00:00:00 +0000 UTC

但问题是rank.DateCreation是假的:

pgadmin

我不明白为什么我有:0001-01-01 00:00:00 0000 UTC for dateCreation . 它似乎也是一个空白值

值应为:2018-06-23 13:34:11 02

这是我的db pg admin view of my db的pg管理员视图

编辑:

这是我的db的创建脚本:

"dateCreation" timestamp with time zone,
  score timestamp with time zone,
  rank timestamp with time zone,

问题可能是:

“dateCreation”带时区的时间戳

, 报价单 .

那么如何用引用来映射这个字段呢?

感谢致敬