From 43c1b75f0b22bab4dbc7d749e1075c65d88b262b Mon Sep 17 00:00:00 2001 From: Joshua Conero Date: Mon, 16 Dec 2024 22:35:12 +0800 Subject: [PATCH] pref(str): TimeParse The string parses the date using the local time instead of the UTC time to avoid errors caused by time zones --- ChangeLog_zh-CN.md | 4 +++- str/time_parse.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog_zh-CN.md b/ChangeLog_zh-CN.md index 55dfffe..d36dc13 100644 --- a/ChangeLog_zh-CN.md +++ b/ChangeLog_zh-CN.md @@ -43,10 +43,12 @@ - **cli** - pref: 系统自定 help 命令,为空时对其进行介绍而非空 - - **secure/aesutil** - feat: 新增 Aes CBC、CFB、GCM、CTR,OFB模式加解密函数 - feat: 新增 Pkcs#7、Zero Padding,用于填充或还原变量 +- **str** + - pref: TimeParse 字符串解析日期使用本地时间代替UTC时间,以避免因时区引起的误差 + diff --git a/str/time_parse.go b/str/time_parse.go index fb292dc..ccbc8a8 100644 --- a/str/time_parse.go +++ b/str/time_parse.go @@ -12,7 +12,7 @@ func TimeParse(tmStr string) (time.Time, error) { if err != nil { return time.Time{}, err } - return time.Parse(layout, tmStr) + return time.ParseInLocation(layout, tmStr, time.Local) } type TimeLayoutDetector struct {