我从API (Jira)收到以下日期格式,需要使用json对其进行解组。我尝试过一种自定义的解组方法,但它不能解析日期,也不能说明原因。
"2020-10-21T05:00:57.258Z“
type CustomTime struct {
time.Time
}
const ctLayout = "2021-02-04T08:18:40.812-0600"
const ctLayoutWithZ = "2021-02-04T08:18:40.812Z"
// Implement Marshaler and Unmarshaler interface
func (j *CustomTime) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
t, err := time.Parse(ctLayout, s)
if err != nil {
t, err = time.Parse(ctLayoutWithZ, s)
if (err != nil) {
return err
}
}
j.Time = t
return nil
}
func (j CustomTime) MarshalJSON() ([]byte, error) {
return json.Marshal(j)
}
编辑我想实际上是这个日期不能解析: 2021-03-23T14:31:27.672-0500