This commit is contained in:
CyJaySong 2023-07-27 18:00:03 +08:00
parent 6c8799fdea
commit fff2adbf77
1 changed files with 5 additions and 1 deletions

View File

@ -85,8 +85,12 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
if err != nil { if err != nil {
return nil, err return nil, err
} }
currentDate := time.Now()
// add current date for correct time locations
dt = dt.AddDate(currentDate.Year(), int(currentDate.Month()), currentDate.Day())
dt = dt.In(convertedLocation) dt = dt.In(convertedLocation)
dt = time.Date(0, 1, 1, dt.Hour(), dt.Minute(), dt.Second(), 0, convertedLocation) // back to zero year
dt = dt.AddDate(-currentDate.Year(), int(-currentDate.Month()), -currentDate.Day())
return &dt, nil return &dt, nil
} else { } else {
i, err := strconv.ParseInt(s, 10, 64) i, err := strconv.ParseInt(s, 10, 64)