时间由指针改回对象

This commit is contained in:
hoteas
2022-10-20 09:08:23 +08:00
parent 56f4911459
commit ea932a032b
7 changed files with 883 additions and 880 deletions
+12 -12
View File
@@ -97,7 +97,7 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
return v
}
func ObjToTime(obj interface{}, e ...*Error) *time.Time {
func ObjToTime(obj interface{}, e ...*Error) time.Time {
tInt := ObjToInt64(obj)
//字符串类型,只支持标准mysql datetime格式
@@ -107,27 +107,27 @@ func ObjToTime(obj interface{}, e ...*Error) *time.Time {
if len(tStr) > 18 {
t, e := time.Parse("2006-01-02 15:04:05", tStr)
if e == nil {
return &t
return t
}
} else if len(tStr) > 15 {
t, e := time.Parse("2006-01-02 15:04", tStr)
if e == nil {
return &t
return t
}
} else if len(tStr) > 12 {
t, e := time.Parse("2006-01-02 15", tStr)
if e == nil {
return &t
return t
}
} else if len(tStr) > 9 {
t, e := time.Parse("2006-01-02", tStr)
if e == nil {
return &t
return t
}
} else if len(tStr) > 6 {
t, e := time.Parse("2006-01", tStr)
if e == nil {
return &t
return t
}
}
@@ -136,27 +136,27 @@ func ObjToTime(obj interface{}, e ...*Error) *time.Time {
//纳秒级别
if len(ObjToStr(tInt)) > 16 {
t := time.Time{}.Add(time.Nanosecond * time.Duration(tInt))
return &t
return t
//微秒级别
} else if len(ObjToStr(tInt)) > 13 {
t := time.Time{}.Add(time.Microsecond * time.Duration(tInt))
return &t
return t
//毫秒级别
} else if len(ObjToStr(tInt)) > 10 {
t := time.Time{}.Add(time.Millisecond * time.Duration(tInt))
return &t
return t
//秒级别
} else if len(ObjToStr(tInt)) > 9 {
t := time.Time{}.Add(time.Second * time.Duration(tInt))
return &t
return t
} else if len(ObjToStr(tInt)) > 3 {
t, e := time.Parse("2006", ObjToStr(tInt))
if e == nil {
return &t
return t
}
}
return nil
return time.Time{}
}
func ObjToFloat64(obj interface{}, e ...*Error) float64 {