mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
add short datetime string parsing support for package gtime
This commit is contained in:
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user