- 通过loc参数指定
Asia/Shanghai
。
type DatabaseConf struct {
Type string `yaml:"type"`
Host string `yaml:"host"`
Port string `yaml:"port"`
User string `yaml:"user"`
Pass string `yaml:"pass"`
DbName string `yaml:"dbName"`
Charset string `yaml:"charset"`
Prefix string `yaml:"prefix"`
IsSingularDbName bool `yaml:"isSingularDbName"`
ParseTime string `yaml:"parseTime"`
Timezone string `yaml:"timezone"`
}
dbConf := config.Conf.Database
connects := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=%s&parseTime=%s&loc=%s", dbConf.User, dbConf.Pass, dbConf.Host, dbConf.Port,
dbConf.DbName, dbConf.Charset, dbConf.ParseTime, dbConf.Timezone)
go get github.com/Gre-Z/common/
安装包, 自定义gin.Model
, 将time.Time
替换为jtime.JsonTime
package models
import (
"github.com/Gre-Z/common/jtime"
)
type Model struct {
ID uint `grom:"primary_key" json:"id"`
CreatedAt jtime.JsonTime `json:"created_at"`
UpdatedAt jtime.JsonTime `json:"updated_at"`
DeletedAt jtime.JsonTime `json:"deleted_at"`
}
- 即可正常显示时间