This commit is contained in:
CyJaySong 2023-07-26 15:51:03 +08:00
parent 9e362d7913
commit 82327cba2f
1 changed files with 2 additions and 5 deletions

View File

@ -45,6 +45,7 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
if err != nil {
return nil, err
}
dt.IsZero()
dt = dt.In(convertedLocation)
return &dt, nil
} else if len(s) >= 21 && s[10] == 'T' && s[19] == '.' {
@ -81,16 +82,12 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
dt = dt.In(convertedLocation)
return &dt, nil
} else if len(s) == 8 && s[2] == ':' && s[5] == ':' {
currentDate := time.Now()
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
if err != nil {
return nil, err
}
// add current date for correct time locations
dt = dt.AddDate(currentDate.Year(), int(currentDate.Month()), currentDate.Day())
dt = dt.In(convertedLocation)
// back to zero year
dt = dt.AddDate(-currentDate.Year(), int(-currentDate.Month()), -currentDate.Day())
dt = time.Date(1, 1, 1, dt.Hour(), dt.Minute(), dt.Second(), 0, convertedLocation)
return &dt, nil
} else {
i, err := strconv.ParseInt(s, 10, 64)