From 24b6558033ffe202bf42f0f3b870dcc798dd2ba8 Mon Sep 17 00:00:00 2001 From: emacsist Date: Wed, 16 Nov 2016 09:33:54 +0800 Subject: [PATCH] Add "yyyy-MM-dd HH:mm:ss" string format --- cast_test.go | 7 +++++++ caste.go | 1 + 2 files changed, 8 insertions(+) diff --git a/cast_test.go b/cast_test.go index 6b73ff8..2e418ec 100644 --- a/cast_test.go +++ b/cast_test.go @@ -212,3 +212,10 @@ func TestToDuration(t *testing.T) { assert.Equal(t, v.expected, ToDuration(v.input)) } } + +func TestStringToDate(t *testing.T) { + d := "2016-03-06 15:28:01" + format := "2006-01-02 15:04:05" + v, _ := time.Parse(format, d) + assert.Equal(t, ToTime(d), v) +} diff --git a/caste.go b/caste.go index 23f59a1..23f0fe8 100644 --- a/caste.go +++ b/caste.go @@ -513,6 +513,7 @@ func StringToDate(s string) (time.Time, error) { "02 Jan 2006", "2006-01-02 15:04:05 -07:00", "2006-01-02 15:04:05 -0700", + "2006-01-02 15:04:05", }) }