by Robin at 20240722; fixed Location err #639

Merged
chenhao merged 1 commits from BUG-20240722 into main 2024-07-22 19:23:34 +08:00
1 changed files with 16 additions and 4 deletions

View File

@ -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 {