views:

606

answers:

2

.NET throws an exception trying to parse a datetime string in this format:

Fri, 10 Oct 2008 00:05:51 CST

Convert.ToDateTime("Fri, 10 Oct 2008 00:05:51 CST") results in an exception:

The string was not recognized as a valid DateTime. There is a unknown word starting at index 26

Character 26 obviously being the start of "CST"

In a quick test, PHP and javascript can both parse this string into a date with no problem. Is .NET just full of fail or is there a reasonable explanation?

+3  A: 

http://msdn.microsoft.com/en-us/library/ey1cdcx8.aspx

You need to use the overloaded DateTime.Parse to accurately parse timezones.

FlySwat
+1  A: 

If a specific date and time format will be parsed across different locales, use one of the overloads of the ParseExact method and provide a format specifier.