Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting exception when using DateTime.Parse method

So, i have this string "Date: Mon Jan 03 2011 19:29:44 GMT+0200", and when i use DateTime.Parse(date).ToString(); i'm getting "String was not recognized as a valid DateTime."

If i remove the '+0200' part it works ok, but ofcourse it doesn't show the correct local time. What's wrong with that?

like image 778
user361633 Avatar asked Dec 12 '22 16:12

user361633


1 Answers

From the documentation, it seems that DateTime.Parse() only understands:

  • The GMT designator, used alone, e.g. Mon, Jan 03 2011 17:29:44 GMT, or

  • A time zone offset specified without the GMT designator, e.g. Mon, Jan 03 2011 19:29:44+02:00.

You might want to convert your date string to the second form.

like image 95
Frédéric Hamidi Avatar answered Dec 27 '22 15:12

Frédéric Hamidi