Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML deserialize DateTime Format

Tags:

c#

.net

xml

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

like image 215
user829174 Avatar asked Mar 02 '12 06:03

user829174


1 Answers

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")
like image 152
Kirill Polishchuk Avatar answered Oct 03 '22 09:10

Kirill Polishchuk