- 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 {
|
||||
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)
|
||||
}
|
||||
|
||||
func Str2TimeWithDefault(timeStr string, defValue time.Time) time.Time {
|
||||
timeStr = strings.Replace(timeStr, "T", " ", 1)
|
||||
retVal, err := time.ParseInLocation("2006-1-2 15:4:5", timeStr, time.Local)
|
||||
retVal, err := TryStr2Time(timeStr)
|
||||
if err != nil {
|
||||
return defValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user