You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.4 KiB
70 lines
1.4 KiB
2 years ago
|
package gotime
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
// DiffInHour 相差多少小时
|
||
|
func (p Pro) DiffInHour(t2 time.Time) (hour int64) {
|
||
|
t2.Before(p.Time)
|
||
|
diff := p.Time.Unix() - t2.Unix()
|
||
|
hour = diff / 3600
|
||
|
return hour
|
||
|
}
|
||
|
|
||
|
// DiffInHourWithAbs 相差多少小时(绝对值)
|
||
|
func (p Pro) DiffInHourWithAbs(t2 time.Time) (hour int64) {
|
||
|
p.Time.Before(t2)
|
||
|
diff := t2.Unix() - p.Time.Unix()
|
||
|
hour = diff / 3600
|
||
|
if hour > 0 {
|
||
|
return hour
|
||
|
}
|
||
|
t2.Before(p.Time)
|
||
|
diff = p.Time.Unix() - t2.Unix()
|
||
|
hour = diff / 3600
|
||
|
return hour
|
||
|
}
|
||
|
|
||
|
// DiffInMinutes 相差多少分钟
|
||
|
func (p Pro) DiffInMinutes(t2 time.Time) (hour int64) {
|
||
|
t2.Before(p.Time)
|
||
|
diff := p.Time.Unix() - t2.Unix()
|
||
|
hour = diff / 60
|
||
|
return hour
|
||
|
}
|
||
|
|
||
|
// DiffInMinutesWithAbs 相差多少分钟(绝对值)
|
||
|
func (p Pro) DiffInMinutesWithAbs(t2 time.Time) (hour int64) {
|
||
|
p.Time.Before(t2)
|
||
|
diff := t2.Unix() - p.Time.Unix()
|
||
|
hour = diff / 60
|
||
|
if hour > 0 {
|
||
|
return hour
|
||
|
}
|
||
|
t2.Before(p.Time)
|
||
|
diff = p.Time.Unix() - t2.Unix()
|
||
|
hour = diff / 60
|
||
|
return hour
|
||
|
}
|
||
|
|
||
|
// DiffInSecond 相差多少秒
|
||
|
func (p Pro) DiffInSecond(t2 time.Time) (hour int64) {
|
||
|
t2.Before(p.Time)
|
||
|
diff := p.Time.Unix() - t2.Unix()
|
||
|
hour = diff
|
||
|
return hour
|
||
|
}
|
||
|
|
||
|
// DiffInSecondWithAbs 相差多少秒(绝对值)
|
||
|
func (p Pro) DiffInSecondWithAbs(t2 time.Time) (hour int64) {
|
||
|
p.Time.Before(t2)
|
||
|
diff := t2.Unix() - p.Time.Unix()
|
||
|
hour = diff
|
||
|
if hour > 0 {
|
||
|
return hour
|
||
|
}
|
||
|
t2.Before(p.Time)
|
||
|
diff = p.Time.Unix() - t2.Unix()
|
||
|
hour = diff
|
||
|
return hour
|
||
|
}
|