// UnmarshalXML parses date from Expiration and validates date format
func (eDate *ExpirationDate) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error {
var dateStr string // zp: 表示時間和時區(qū),如2020-11-08T00:00:00Z忍级;2020-11-08T00:00:00+08:00
err := d.DecodeElement(&dateStr, &startElement)
if err != nil {
return err
}
// While AWS documentation mentions that the date specified
// must be present in ISO 8601 format, in reality they allow
// users to provide RFC 3339 compliant dates.
expDate, err := time.Parse(time.RFC3339, dateStr) // zp: 解析成time
if err != nil {
return errLifecycleInvalidDate
}
// Allow only date timestamp specifying midnight GMT
hr, min, sec := expDate.Clock()
nsec := expDate.Nanosecond()
loc := expDate.Location()
if !(hr == 0 && min == 0 && sec == 0 && nsec == 0 && loc.String() == time.UTC.String()) { // zp: 判斷時區(qū)得运,time.UTC.String返回"UTC"
return errLifecycleDateNotMidnight
}
*eDate = ExpirationDate{expDate}
return nil
}
上面這段代碼來自minio
若dateStr
是"2020-11-08T00:00:00+08:00"則loc.String
返回的是Local
若dateStr
是"2020-11-08T00:00:00Z"則loc.String
返回的是UTC
活箕,即若希望才有RFC3339解析時時區(qū)采用UTC格式讼庇,則格式應該是"2020-11-08T00:00:00Z"
rfc3339 是一種包含時區(qū)信息的字符串標準格式。格式為YYYY-MM-DDTHH:mm:ss+TIMEZONE敏晤,YYYY-MM-DD表示年月日搜变,T出現(xiàn)在字符串中,表示time元素的開頭瓶竭,HH:mm:ss表示時分秒督勺,TIMEZONE表示時區(qū)(+08:00表示東八區(qū)時間,領先UTC 8小時斤贰,即北京時間)智哀。