String '3/18/09 10:16 PM' is not a valid AllXsd value

Obviously, the reader does not like this format coming from the XML response.

I wonder if I can reformat this. Trying to convert to DateTime using the following code with my XmlReader :

 reader.ReadContentAsDateTime(); 
+42
c # xml parsing
Mar 19 '09 at 11:41
source share
2 answers

Xml readers usually expect dates / times in a very specific format; you can use it yourself using XmlConvert :

 string s = XmlConvert.ToString(DateTime.Now); DateTime when = XmlConvert.ToDateTime(s); 

If you are using something else, you will need to read it as a string and use DateTime.TryParseExact (or similar) to indicate the actual format string:

 string s = reader.ReadContentAsString(); DateTime when = DateTime.ParseExact(s, "M/d/yy hh:mm tt", CultureInfo.InvariantCulture); 

If you use XmlSerializer , you can use the shim property for conversion - let me know if that is what you are doing ...

+44
Mar 19 '09 at 11:46
source share

According to the XML schema specification, the date values ​​must be in ISO8601 format, for example, something like

 2009-03-13T22:16:00 
+81
Mar 19 '09 at 11:48
source share



All Articles