字符串“09年3月18日下午10点16分'不是一个有效的AllXsd值 [英] The string '3/18/09 10:16 PM' is not a valid AllXsd value
问题描述
显然,读者不喜欢这种格式从响应XML传入。
想知道如果我可以重新格式化此。尝试使用以下code。与转换为的DateTime
我的的XmlReader
:
reader.ReadContentAsDateTime();
XML读者普遍预期日期/在一个非常特定的格式倍;您可以通过使用自己的 XmlConvert
:
字符串s = XmlConvert.ToString(DateTime.Now);
当日期时间= XmlConvert.ToDateTime(S);
如果您使用的是别的东西,你必须阅读它作为一个字符串,并使用 DateTime.TryParseExact
(或类似)来指定实际的格式字符串:
字符串s = reader.ReadContentAsString();
当日期时间= DateTime.ParseExact(S,M / D / YY HH:MM TT
CultureInfo.InvariantCulture);
如果您使用的是的XmlSerializer
,你可以使用一个垫片属性进行转换 - 让我知道,如果这是你在做什么...
Obviously the reader doesn't like this format incoming from the response XML.
Wondering if I can reformat this. Trying to convert to DateTime
using the following code with my XmlReader
:
reader.ReadContentAsDateTime();
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...
这篇关于字符串“09年3月18日下午10点16分'不是一个有效的AllXsd值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!