According to the XML schema spec, date time values should be in ISO8601 format, e.g., something like
2009-03-13T22:16:00
Xml readers generally expect dates/times in a very specific format; you can use this yourself using XmlConvert
:
string s = XmlConvert.ToString(DateTime.Now);
DateTime when = XmlConvert.ToDateTime(s);
If you are using something else, you'll have to read it as a string and use DateTime.TryParseExact
(or similar) to specify the actual format string:
string s = reader.ReadContentAsString();
DateTime when = DateTime.ParseExact(s, "M/d/yy hh:mm tt",
CultureInfo.InvariantCulture);
If you are using XmlSerializer
, you could use a shim property to do the conversion - let me know if this is what you are doing...
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