我有通過 REST API 檢索的 XML 數(shù)據(jù),我將其解組到 GO 結(jié)構(gòu)中。其中一個(gè)字段是日期字段,但是 API 返回的日期格式與默認(rèn)的 time.Time 解析格式不匹配,因此解組失敗。有什么方法可以指定解組函數(shù)在 time.Time 解析中使用哪種日期格式?我想使用正確定義的類型并使用字符串來保存日期時(shí)間字段感覺不對。示例結(jié)構(gòu):type Transaction struct { Id int64 `xml:"sequencenumber"` ReferenceNumber string `xml:"ourref"` Description string `xml:"description"` Type string `xml:"type"` CustomerID string `xml:"namecode"` DateEntered time.Time `xml:"enterdate"` //this is the field in question Gross float64 `xml:"gross"` Container TransactionDetailContainer `xml:"subfile"`}返回的日期格式為“yyyymmdd”。
- 3 回答
- 0 關(guān)注
- 207 瀏覽
添加回答
舉報(bào)
0/150
提交
取消