我试图在 Go 中获得两个日期之间的天数,但是当我得到时间(小时)的差异,然后除以每天的时间量时,我遇到了一个问题。
问题:如果日期不同(5 月 7 日和 5 月 8 日)但两者之间的时间低于 24 小时,我的代码会计算在内,因为两者之间没有天数。
我想要的是:计算中间的真实天数。
// Days
firstDay := firstDate.Unix()
lastDay := lastDate.Unix()
fmt.Println("firstDay: ", firstDay)
fmt.Println("lastDay: ", lastDay)
if firstDay > lastDay {
fmt.Println("IS TO SMALL")
return
}
// businessDays =
businessDays := (lastDay - firstDay) / 86400
fmt.Println("businessDays: ", businessDays)
Run Code Online (Sandbox Code Playgroud)
非常感谢。
go ×1