Parsing a DateTime containing milliseconds fails for certain cultures. Why?
Posted
by dradovic
on Stack Overflow
See other posts from Stack Overflow
or by dradovic
Published on 2010-05-11T13:48:07Z
Indexed on
2010/05/11
13:54 UTC
Read the original article
Hit count: 348
I'm trying to parse a string containing milliseconds like this:
string s = "11.05.2010 15:03:08.7718687"; // culture: de-CH DateTime d = DateTime.Parse(s); // works
However, for example under the de-DE locale, the decimal separator is a comma (not a dot). So the example becomes:
string s = "11.05.2010 15:03:08,7718687"; // culture: de-DE (note the comma) DateTime d = DateTime.Parse(s); // throws a FormatException
It is weird to me that DateTime.Parse(s) should throw a FormatException now as it is supposed to use the CultureInfo.CurrentCulture to do the parsing. Even passing the CurrentCulture as an argument explicitly does not help neither. Does anybody have an idea why this does not work? Doesn't parsing take the NumberFormatInfo.NumberDecimalSeparator into account?
© Stack Overflow or respective owner