Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing a Date with Month name to C# DateTime

Tags:

c#

datetime

I want to parse the following date format to a DateTime object in C#.

"19 Aug 2010 17:48:35 GMT+00:00"

How can I accomplish this?

like image 999
iosdevnyc Avatar asked Aug 19 '10 18:08

iosdevnyc


1 Answers

I'd recommend using DateTime.ParseExact.

DateTime.ParseExact(dateString, "dd MMM yyyy H:mm:ss \\G\\M\\Tzzz", System.Globalization.CultureInfo.InvariantCulture);

As suggested in the comments below, System.Globalization.CultureInfo.CurrentCulture is a good thing to be aware of and use if you are doing a desktop application.

like image 111
Matt DeKrey Avatar answered Sep 20 '22 12:09

Matt DeKrey