From 05a328e34493b5c96c88b8ff285e2f3107aae6e0 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Tue, 27 Jun 2023 16:55:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E8=BE=85=E5=8A=A9=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/times/helper.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/utils/times/helper.go b/utils/times/helper.go index 04d1926..4362cc2 100644 --- a/utils/times/helper.go +++ b/utils/times/helper.go @@ -98,3 +98,15 @@ func GetDeltaWeek(t1, t2 time.Time) int { t1, t2 = GetMondayZero(t1), GetMondayZero(t2) return GetDeltaDay(t1, t2) / 7 } + +// GetHSMFromString 从时间字符串中获取时分秒 +func GetHSMFromString(timeStr, layout string) (hour, min, sec int) { + t, _ := time.ParseInLocation(layout, timeStr, time.Local) + return t.Hour(), t.Minute(), t.Second() +} + +// GetTimeFromString 将时间字符串转化为时间 +func GetTimeFromString(timeStr, layout string) time.Time { + t, _ := time.ParseInLocation(layout, timeStr, time.Local) + return t +}