From 2c0c33e59482f2fa95ebed9e9fe4a0ba0a1ac33b Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Tue, 23 May 2023 11:13:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E4=B8=8B=E4=B8=80=E4=B8=AAN?= =?UTF-8?q?=E7=A7=92=E5=9C=A8=E5=A4=9A=E5=B0=91=E7=A7=92=E4=B9=8B=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/times/calc.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 utils/times/calc.go diff --git a/utils/times/calc.go b/utils/times/calc.go new file mode 100644 index 0000000..83d6a87 --- /dev/null +++ b/utils/times/calc.go @@ -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) +}