Can you specify format for XmlSerialization of a datetime?

前端 未结 2 980
孤街浪徒
孤街浪徒 2020-11-27 06:01

I need to serialize / deserialize a datetime into yyyyMMdd format for an XML file. Is there an attribute / workaround I can use for this?

2条回答
  •  时光取名叫无心
    2020-11-27 06:37

    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.

提交回复
热议问题