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{