自定义 time.Time 转 json 格式

This commit is contained in:
Shikong 2022-10-05 00:20:43 +08:00
parent 9ba7ab03b0
commit 45cb7c1c66

View File

@ -11,7 +11,7 @@ const (
timeFormat = "2006-01-02 15:04:05"
)
// MarshalJSON on JsonTime format Time field with %Y-%m-%d %H:%M:%S
// MarshalJSON on Json Time format Time field with %Y-%m-%d %H:%M:%S
func (t Time) MarshalJSON() ([]byte, error) {
// 重写time转换成json之后的格式
var tmp = fmt.Sprintf("\"%s\"", time.Time(t).Format(timeFormat))