mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
add short datetime string parsing support for package gtime
This commit is contained in:
parent
5adde275fc
commit
285ad36e7d
@ -45,7 +45,7 @@ const (
|
||||
// "2018/10/31 - 16:38:46"
|
||||
// "2018-02-09",
|
||||
// "2018.02.09",
|
||||
timeRegexPattern1 = `(\d{4}[-/\.]\d{2}[-/\.]\d{2})[:\sT-]*(\d{0,2}:{0,1}\d{0,2}:{0,1}\d{0,2}){0,1}\.{0,1}(\d{0,9})([\sZ]{0,1})([\+-]{0,1})([:\d]*)`
|
||||
timeRegexPattern1 = `(\d{4}[-/\.]\d{1,2}[-/\.]\d{1,2})[:\sT-]*(\d{0,2}:{0,1}\d{0,2}:{0,1}\d{0,2}){0,1}\.{0,1}(\d{0,9})([\sZ]{0,1})([\+-]{0,1})([:\d]*)`
|
||||
|
||||
// Regular expression2(datetime separator supports '-', '/', '.').
|
||||
// Eg:
|
||||
|
@ -42,6 +42,12 @@ func Test_New(t *testing.T) {
|
||||
timeTemp := gtime.New(timeNow.TimestampMicro())
|
||||
t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), timeNow.Time.Format("2006-01-02 15:04:05"))
|
||||
})
|
||||
// short datetime.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
timeTemp := gtime.New("2021-2-9 08:01:21")
|
||||
t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2021-02-09 08:01:21")
|
||||
t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2021-02-09 08:01:21")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Nil(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user