Skip to content

encoding/xml: MarshalXML interface is not good enough #2771

Closed
@mark-summerfield

Description

@mark-summerfield
Using ISO8601 is more compact and more accurate as the code below shows:

package main
import (
   "fmt"
   "os"
   "encoding/xml"
   "encoding/json"
   "time"
   )
func main() {
   type T struct { When time.Time `xml:",attr"` }
   t := &T{time.Now()}
   xml.Marshal(os.Stdout, t)
   j, _ := json.Marshal(t)
   fmt.Println(string(j))
}
// Output:

<T When="Mon Jan 16 12:29:28 +0000 GMT 2012"></T>
{"When":"2012-01-16T12:29:28.802511Z"}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions