From 5d938da53e71869b7a62e2a68983480a2de0b378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Sat, 10 Jun 2023 11:37:52 +0800 Subject: [PATCH] =?UTF-8?q?enhance(types):=E4=BF=AE=E6=AD=A3=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=97=B6=E9=97=B4=E8=A7=A3=E6=9E=90=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/date.go | 2 +- types/datetime.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/types/date.go b/types/date.go index 7e08394..d1703aa 100644 --- a/types/date.go +++ b/types/date.go @@ -11,7 +11,7 @@ import ( ) var dateLayouts = []string{ - "2006-01-02", "2006-1-2", "2006/01/02", "6-1-2", "6-01-02", "01/02/06", "1/2/6", "2006年01月02日", "06年1月2日", + "2006-01-02", "2006-1-2", "2006/01/02", "06-1-2", "6-01-02", "01/02/06", "1/2/06", "2006年01月02日", "06年1月2日", } type Date struct { diff --git a/types/datetime.go b/types/datetime.go index 6d70a42..78a4066 100644 --- a/types/datetime.go +++ b/types/datetime.go @@ -13,7 +13,8 @@ import ( var ( loc *time.Location = time.FixedZone("+0800", 8*60*60) datetimeLayouts = []string{ - "2006-01-02 15:04:05", "2006-1-2 15:04:05", "2006/01/02 15:04:05", "6-1-2 15:04:05", "6-01-02 15:04:05", "01/02/06 15:04:05", "1/2/6 15:04:05", "2006年01月02日 15:04:05", "06年1月2日 15:04:05", + "2006-01-02 15:04:05", "2006-1-2 15:04:05", "2006/01/02 15:04:05", "06-1-2 15:04:05", "06-01-02 15:04:05", "01/02/06 15:04:05", "1/2/06 15:04:05", "2006年01月02日 15:04:05", "06年1月2日 15:04:05", + "2006-01-02 15:04", "2006-1-2 15:04", "2006/01/02 15:04", "06-1-2 15:04", "06-01-02 15:04", "01/02/06 15:04", "1/2/06 15:04", "2006年01月02日 15:04", "06年1月2日 15:04", } ) @@ -49,6 +50,7 @@ func ParseDateTime(t string) (DateTime, error) { return NewEmptyDateTime(), fmt.Errorf("不能解析空白的日期时间。") } for _, layout := range datetimeLayouts { + fmt.Printf("Parse: %s, Try layout: %s\n", t, layout) d, err := time.ParseInLocation(layout, t, loc) if err == nil { return DateTime{