5

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

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
user829174
  • 6,132
  • 24
  • 75
  • 125

2 Answers2

7

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")
Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
0

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

NidhinSPradeep
  • 1,186
  • 2
  • 14
  • 15