diff --git a/server/handler/bills.go b/server/handler/bills.go index 1b43a07..1857a0d 100644 --- a/server/handler/bills.go +++ b/server/handler/bills.go @@ -24,9 +24,9 @@ type ListBillsRequest struct { // ListBillsResponse 账单列表响应 type ListBillsResponse struct { - Result bool `json:"result"` - Message string `json:"message,omitempty"` - Data *ListBillsData `json:"data,omitempty"` + Result bool `json:"result"` + Message string `json:"message,omitempty"` + Data *ListBillsData `json:"data,omitempty"` } // ListBillsData 账单列表数据 @@ -69,13 +69,15 @@ func ListBills(c *gin.Context) { if req.StartDate != "" || req.EndDate != "" { timeFilter := make(map[string]interface{}) if req.StartDate != "" { - startTime, err := time.Parse("2006-01-02", req.StartDate) + // 使用本地时区解析日期,避免 UTC 时区问题 + startTime, err := time.ParseInLocation("2006-01-02", req.StartDate, time.Local) if err == nil { timeFilter["$gte"] = startTime } } if req.EndDate != "" { - endTime, err := time.Parse("2006-01-02", req.EndDate) + // 使用本地时区解析日期,避免 UTC 时区问题 + endTime, err := time.ParseInLocation("2006-01-02", req.EndDate, time.Local) if err == nil { // 结束日期包含当天,所以加一天 endTime = endTime.Add(24 * time.Hour) diff --git a/server/service/bill.go b/server/service/bill.go index da931b0..100fb45 100644 --- a/server/service/bill.go +++ b/server/service/bill.go @@ -489,13 +489,14 @@ func saveCleanedBillsFromJSON(filePath, billType, sourceFile, uploadBatch string } // parseTime 解析时间字符串 +// 使用本地时区解析,避免 UTC 时区问题 func parseTime(s string) time.Time { s = strings.TrimSpace(s) if s == "" { return time.Time{} } - // 尝试多种时间格式 + // 尝试多种时间格式(使用本地时区) formats := []string{ "2006-01-02 15:04:05", "2006/01/02 15:04:05", @@ -506,7 +507,7 @@ func parseTime(s string) time.Time { } for _, format := range formats { - if t, err := time.Parse(format, s); err == nil { + if t, err := time.ParseInLocation(format, s, time.Local); err == nil { return t } }