Can you specify format for XmlSerialization of a datetime? Can you specify format for XmlSerialization of a datetime? xml xml

Can you specify format for XmlSerialization of a datetime?


No, there isn't. If it's in that format, then it's not a valid dateTime as far as XML Schema is concerned.

The best you can do is as follows:

[XmlIgnore]public DateTime DoNotSerialize {get;set;}public string ProxyDateTime {    get {return DoNotSerialize.ToString("yyyyMMdd");}    set {DoNotSerialize = DateTime.Parse(value);}}


XmlElementAttribute#DataType should provide what you need:

[XmlElement(DataType="date")]    public DateTime Date1 {get;set;}

This will get Date1 property serialized to the proper xml date format.