fix: utc time

This commit is contained in:
engigu
2025-10-20 21:22:44 +08:00
parent c3e5fa2003
commit 953f744846
+6 -2
View File
@@ -15,7 +15,9 @@ type Time time.Time
func (t Time) MarshalJSON() ([]byte, error) { func (t Time) MarshalJSON() ([]byte, error) {
b := make([]byte, 0, len(timeFormat)+2) b := make([]byte, 0, len(timeFormat)+2)
b = append(b, '"') b = append(b, '"')
b = time.Time(t).AppendFormat(b, timeFormat) // 转换到东八区时间再格式化
loc, _ := time.LoadLocation(timezone)
b = time.Time(t).In(loc).AppendFormat(b, timeFormat)
b = append(b, '"') b = append(b, '"')
return b, nil return b, nil
@@ -28,7 +30,9 @@ func (t *Time) UnmarshalJSON(data []byte) (err error) {
} }
func (t Time) String() string { func (t Time) String() string {
return time.Time(t).Format(timeFormat) // 转换到东八区时间再格式化
loc, _ := time.LoadLocation(timezone)
return time.Time(t).In(loc).Format(timeFormat)
} }
func (t Time) local() time.Time { func (t Time) local() time.Time {