From 0cfaa799f50cdc659c8da20de4754ee0266c5ce2 Mon Sep 17 00:00:00 2001 From: ayflying Date: Tue, 25 Feb 2025 16:38:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=BC=A0=E5=85=A5=E4=B8=8D?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/time.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/time.go b/tools/time.go index 5a9cfed..ec87623 100644 --- a/tools/time.go +++ b/tools/time.go @@ -19,13 +19,13 @@ func (m *timeMod) Load() { // 获取本周的开始时间 func (m *timeMod) StartOfWeek(t time.Time) time.Time { start := gtime.New().AddDate(0, 0, -int(t.Weekday()-1)).Time - start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.UTC().Location()) + start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location()) return start } func (m *timeMod) StartOfWeekV2(t time.Time) time.Time { start := t.AddDate(0, 0, -int(t.Weekday()-1)) - start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.UTC().Location()) + start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location()) return start } @@ -59,15 +59,14 @@ func (m *timeMod) GetDayPass(startTime time.Time, t ...time.Time) int { month := startTime.Month() day := startTime.Day() // 构建一天的开始时间 - startTime = time.Date(year, month, day, 0, 0, 0, 0, startTime.UTC().Location()) - + startTime = time.Date(year, month, day, 0, 0, 0, 0, startTime.Location()) //如果为空,使用当前时间 endTime := time.Now() if len(t) > 0 { endTime = t[0] } //计算过去了多少天 - dayPass := int(endTime.Sub(startTime).Hours() / 24) + dayPass := int(endTime.UTC().Sub(startTime.UTC()).Hours() / 24) return dayPass } @@ -89,7 +88,7 @@ func (m *timeMod) GetDayZeroTime(currentTime time.Time, day int) time.Time { // 加上指定天数的时间 threeDaysLater := currentTime.AddDate(0, 0, day) // 调整时间为0点 - zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 0, 0, 0, 0, threeDaysLater.UTC().Location()) + zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 0, 0, 0, 0, threeDaysLater.Location()) return zeroTime } @@ -108,7 +107,7 @@ func (m *timeMod) GetEndTime(startTime time.Time, _day ...int) time.Time { // 加上指定天数的时间 threeDaysLater := startTime.AddDate(0, 0, day) // 调整时间为0点 - zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 23, 59, 59, 0, threeDaysLater.UTC().Location()) + zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 23, 59, 59, 0, threeDaysLater.Location()) return zeroTime }