You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
280 B
Go

7 months ago
package custom
import "time"
type DateTime struct {
time.Time
}
// MarshalJSON 实现json.Marshaler接口自定义序列化格式
func (dt DateTime) MarshalJSON() ([]byte, error) {
formatted := `"` + dt.Format("2006-01-02 15:04:05") + `"`
return []byte(formatted), nil
}