From 761934e1fa7317a7d3f08bc32b726e0482906459 Mon Sep 17 00:00:00 2001 From: shockerli Date: Tue, 28 Nov 2023 17:45:08 +0800 Subject: [PATCH] Support `cvt.TimeFormats` to add custom time format --- time.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/time.go b/time.go index bf2c692..1f2df4b 100644 --- a/time.go +++ b/time.go @@ -94,7 +94,9 @@ func TimeInLocationE(val interface{}, loc *time.Location) (t time.Time, err erro return t, newErr(val, "time.Time") } -var timeFormats = []string{ +// TimeFormats all supported time formats +// you can add your custom time format +var TimeFormats = []string{ time.RFC3339, time.RFC1123Z, time.RFC1123, @@ -144,7 +146,7 @@ var timeFormats = []string{ } func parseDate(s string, loc *time.Location) (t time.Time, err error) { - for _, dateType := range timeFormats { + for _, dateType := range TimeFormats { if t, err = time.ParseInLocation(dateType, s, loc); err == nil { return }