feat: 增加时间转换辅助函数

This commit is contained in:
kercylan98 2023-06-27 16:55:33 +08:00
parent 83531b65c6
commit 05a328e344
1 changed files with 12 additions and 0 deletions

View File

@ -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
}