I'm serializing class which contains DateTime property.
public DateTime? Delivered { get; set; }
After serializing Delivered node contains DateTime formatted like this:
2008-11-20T00:00:00
How can I change this property to make it look like this:
2008-11-20 00:00:00
Thanks in advance
The hack I use for odd formatting during XmlSerialization is to have a special property that is only used during XmlSerialization
//normal DateTime accessor
[XmlIgnore]
public DateTime Delivered { get; set; }
//special XmlSerialization accessor
[XmlAttribute("DateTime")]
public string XmlDateTime
{
get { return this.Delivered.ToString("o"); }
set { this.Delivered = new DateTime.Parse(value); }
}
Take a look at XmlAttributeOverrides class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With