3

.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?

1
  • Javascript runs on the client, so it can use the locale settings of that computer...PHP is just cruddy and probably assumes. .NET forces you to write culture independent code, so its a little trickier. Commented Oct 10, 2008 at 22:13

2 Answers 2

2

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.