From b1756d3c3d767873647c6ab5785e8d02be8433ac Mon Sep 17 00:00:00 2001 From: Leufolium Date: Mon, 22 Jul 2024 19:23:13 +0800 Subject: [PATCH] by Robin at 20240722; fixed Location err --- bizcommon/util/util.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bizcommon/util/util.go b/bizcommon/util/util.go index d155d84d..af1782cd 100644 --- a/bizcommon/util/util.go +++ b/bizcommon/util/util.go @@ -83,7 +83,10 @@ func Convert2SqlArr(a ...any) string { // 获取整点时间戳 func GetHourStartTimeStamp(t time.Time) int64 { - loc, _ := time.LoadLocation("Asia/Shanghai") + loc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + loc = time.FixedZone("CST", 8*3600) + } timeStr := fmt.Sprintf("%02d-%02d-%02d %02d:00:00", t.Year(), t.Month(), t.Day(), t.Hour()) duetimecst, err := time.ParseInLocation("2006-1-2 15:04:05", timeStr, loc) if err != nil { @@ -94,7 +97,10 @@ func GetHourStartTimeStamp(t time.Time) int64 { // 获取30分时间戳 func GetHourHalfTimeStamp(t time.Time) int64 { - loc, _ := time.LoadLocation("Asia/Shanghai") + loc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + loc = time.FixedZone("CST", 8*3600) + } timeStr := fmt.Sprintf("%02d-%02d-%02d %02d:30:00", t.Year(), t.Month(), t.Day(), t.Hour()) duetimecst, err := time.ParseInLocation("2006-1-2 15:04:05", timeStr, loc) if err != nil { @@ -105,7 +111,10 @@ func GetHourHalfTimeStamp(t time.Time) int64 { // 获取整分时间戳 func GetMinuteStartTimeStamp(t time.Time) int64 { - loc, _ := time.LoadLocation("Asia/Shanghai") + loc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + loc = time.FixedZone("CST", 8*3600) + } timeStr := fmt.Sprintf("%02d-%02d-%02d %02d:%02d:00", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute()) duetimecst, err := time.ParseInLocation("2006-1-2 15:04:05", timeStr, loc) if err != nil { @@ -123,7 +132,10 @@ func GetTodayZeroTime() time.Time { // 获取0点时间戳 func GetDayStartTimeStamp(t time.Time) int64 { - loc, _ := time.LoadLocation("Asia/Shanghai") + loc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + loc = time.FixedZone("CST", 8*3600) + } timeStr := fmt.Sprintf("%02d-%02d-%02d 00:00:00", t.Year(), t.Month(), t.Day()) duetimecst, err := time.ParseInLocation("2006-1-2 15:04:05", timeStr, loc) if err != nil { -- 2.41.0