对 DATE格式进行转换 #2093
@ -48,6 +48,16 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||
}
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) == 10 && s[4] == '-' {
|
||||
if s == "0000-00-00" || s == "0001-01-01" {
|
||||
return &time.Time{}, nil
|
||||
}
|
||||
dt, err := time.ParseInLocation("2006-01-02", s, originalLocation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else {
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err == nil {
|
||||
|
@ -16,6 +16,7 @@ func TestString2Time(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
var kases = map[string]time.Time{
|
||||
"2021-08-10": time.Date(2021, 8, 10, 8, 0, 0, 0, expectedLoc),
|
||||
"2021-06-06T22:58:20+08:00": time.Date(2021, 6, 6, 22, 58, 20, 0, expectedLoc),
|
||||
"2021-07-11 10:44:00": time.Date(2021, 7, 11, 18, 44, 0, 0, expectedLoc),
|
||||
"2021-08-10T10:33:04Z": time.Date(2021, 8, 10, 18, 33, 04, 0, expectedLoc),
|
||||
|
Loading…
Reference in New Issue
Block a user