我已经在我的数据库 (mySQL) 中存储了这个数据时间字段,last_activity: 2017-06-12 11:07:09
我正在使用参数 parseTime=True
在我的 OpenDB 上
问题是输出是:last activity: {63632862429 0 <nil>}
而不是 2017-06-12 11:07:09
我做错了什么?
谢谢
type DateType time.Time
type User struct {
LastActivity DateType
}
func (stUser *User) GetUserDataByLogin(login string) {
db := OpenDB()
defer db.Close()
// Test the connection to the database
err := db.Ping()
checkErr(err)
err = db.QueryRow("SELECT last_activity FROM users WHERE login = ?", login).Scan(&stUser.LastActivity)
if err != nil {
if err == sql.ErrNoRows {
// there were no rows, but otherwise no error occurred
} else {
log.Fatal(err)
}
}
fmt.Println("last activity:", stUser.LastActivity)
最佳答案
您必须像这样声明 DateType.String()
方法:
func (t DateType) String() string {
return time.Time(t).String()
}
The declared type does not inherit any methods bound to the existing type
关于mysql - 在 golang 的 time.time 中从 mysql 检索日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44498738/