我有一个问题,即一个特定的时间字符串,包含Gmail的Atom提要中没有解析使用 DateTime.Parse()
。我明白我可以使用DateTime.TryParse(),但我很好奇,为什么这两个不工作,在所有其余的事情。
2009-12-28T24:11:48Z
2009-12-30T24:16:20Z
具体的例外是:
System.FormatException:由字符串psented日期时间再$ P $是无法在日历System.Globalization.GregorianCalendar支持
我怀疑的是,这是因为在24小时的...而不是00,但我不知道我怎么会纠正这种。
解决方案 私有静态的DateTime ParseDate(字符串s)
{
DateTime的结果;
如果(!DateTime.TryParse(S,出结果))
{
结果= DateTime.ParseExact(S,YYYY-MM-ddT24:毫米:SSK,System.Globalization.CultureInfo.InvariantCulture);
结果= result.AddDays(1);
}
返回结果;
}
I'm having an issue where a specific time string, contained in the Gmail Atom feed isn't parsing using DateTime.Parse()
. I understand I could use DateTime.TryParse(), but I'm curious to why these two don't work, where as all of the rest do.
2009-12-28T24:11:48Z
2009-12-30T24:16:20Z
the specific exception is:
System.FormatException: The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.
My suspicion is that it's because of the hour 24... rather than 00, but I'm not sure how I would rectify that.
解决方案private static DateTime ParseDate(string s)
{
DateTime result;
if (!DateTime.TryParse(s, out result))
{
result = DateTime.ParseExact(s, "yyyy-MM-ddT24:mm:ssK", System.Globalization.CultureInfo.InvariantCulture);
result = result.AddDays(1);
}
return result;
}
相关推荐
最新文章