计算下一个N秒在多少秒之后

This commit is contained in:
kercylan98 2023-05-23 11:13:56 +08:00
parent a31448bf03
commit 2c0c33e594
1 changed files with 19 additions and 0 deletions

19
utils/times/calc.go Normal file
View File

@ -0,0 +1,19 @@
package times
import (
"time"
)
// CalcNextSec 计算下一个N秒在多少秒之后
func CalcNextSec(sec int) int {
now := time.Now().Unix()
next := now + int64(sec) - now%int64(sec)
return int(next - now)
}
// CalcNextSecWithTime 计算下一个N秒在多少秒之后
func CalcNextSecWithTime(t time.Time, sec int) int {
now := t.Unix()
next := now + int64(sec) - now%int64(sec)
return int(next - now)
}