Files
service-common/utils/time.go

27 lines
415 B
Go

package utils
import (
"math"
"time"
)
// CalcDaysDiff 计算两个日期相差多少天
func CalcDaysDiff(one, two time.Time) int32 {
oneZero := time.Date(
one.Year(),
one.Month(),
one.Day(),
0, 0, 0, 0,
time.Local,
)
twoZero := time.Date(
two.Year(),
two.Month(),
two.Day(),
0, 0, 0, 0,
time.Local,
)
// 计算相差天数
return int32(math.Abs(oneZero.Sub(twoZero).Hours() / 24))
}