- TryStr2Time handle time zone info.
This commit is contained in:
@@ -261,12 +261,15 @@ func TryStr2Time(timeStr string) (time.Time, error) {
|
|||||||
if strings.Index(timeStr, " ") == -1 {
|
if strings.Index(timeStr, " ") == -1 {
|
||||||
timeStr += " 00:00:00"
|
timeStr += " 00:00:00"
|
||||||
}
|
}
|
||||||
|
maxTimeStrLen := len("2018-05-03 09:18:40")
|
||||||
|
if len(timeStr) > maxTimeStrLen {
|
||||||
|
timeStr = timeStr[:maxTimeStrLen]
|
||||||
|
}
|
||||||
return time.ParseInLocation("2006-1-2 15:4:5", timeStr, time.Local)
|
return time.ParseInLocation("2006-1-2 15:4:5", timeStr, time.Local)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Str2TimeWithDefault(timeStr string, defValue time.Time) time.Time {
|
func Str2TimeWithDefault(timeStr string, defValue time.Time) time.Time {
|
||||||
timeStr = strings.Replace(timeStr, "T", " ", 1)
|
retVal, err := TryStr2Time(timeStr)
|
||||||
retVal, err := time.ParseInLocation("2006-1-2 15:4:5", timeStr, time.Local)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return defValue
|
return defValue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user