Reputation: 6362
I have an Xml element that needs to contain DateTime of Year, Month, Day, Hour, Min, Sec and MS
I later need that that Xml element be casted via XMLDeserializer, to DateTime object.
I know that there are some issues with DateTime Format casting, My question is what is the DateTime Format that i should write the Xml Element so once i deserialize it via XMLDeserializer i will not have any issues to cast to DateTime object
I would like to have answer like: {0:MM/dd/yy H:mm:ss zzz}
or any other Format that will definatelly work
Upvotes: 5
Views: 7168
Reputation: 1304
I faced same problem. what I did is I created an object of the class and assign value to date time property. Then I serialized the object to get the XML out put. This helped me to find out in what form I should give date time field in my XML document that has to be DE serialized.
It was expecting date filed in below.
2017-06-21T00:00:00+05:30
Upvotes: 0
Reputation: 56162
Internally XmlSerializer
uses XmlConvert
which converts DateTime
using following format:
yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz
Anyway use ISO 8601 format. In .NET you can use o
format specifier:
dateTime.ToString("o")
Upvotes: 7