goProject/trunk/center/common/mytime/timefuncs.go

27 lines
661 B
Go
Raw Permalink Normal View History

2025-01-23 16:12:49 +08:00
package mytime
import (
"goutil/logUtilPlus"
"time"
)
2025-02-08 16:30:07 +08:00
// 计算两个时间戳之间间隔多少天
2025-01-23 16:12:49 +08:00
func DiffDays(new, old int64) int64 {
newZeroTime := ZeroTime(new, 0)
oldZeroTime := ZeroTime(old, 0)
logUtilPlus.ErrorLog("newZeroTime=%d,oldZeroTime=%d", newZeroTime, oldZeroTime)
return newZeroTime/86400 - oldZeroTime/86400
}
func ZeroTime(sec, nsec int64) int64 {
dateStr := time.Unix(sec, nsec).Format("2006-01-02")
t, _ := time.ParseInLocation("2006-01-02", dateStr, time.Local)
return t.Unix()
}
2025-02-08 16:30:07 +08:00
func IsSameDay(first, second int64) bool {
firstZero := ZeroTime(first, 0)
secondZero := ZeroTime(second, 0)
return firstZero == secondZero
}