mirror of
https://gitee.com/shikong-sk/gofiber-study
synced 2025-02-24 15:52:15 +08:00
20 lines
359 B
Go
20 lines
359 B
Go
|
package time
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Time time.Time
|
||
|
|
||
|
const (
|
||
|
timeFormat = "2006-01-02 15:04:05"
|
||
|
)
|
||
|
|
||
|
// MarshalJSON on JsonTime 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))
|
||
|
return []byte(tmp), nil
|
||
|
}
|