Reputation: 1708
Am unable to convert a string which represents date and time ex: "Tue Mar 18 14:37:34 PDT 2014"
to a DateTime object. From the format I can figure it out to be in the RFC 1123 format. What is the best way to parse date strings as above?
Upvotes: 0
Views: 94
Reputation: 29
If you can make the format of the string like this (you are pretty close): Sat, 01 Nov 2008 19:35:00 GMT
You can use DateTime.Parse(dateString);
Find more information here http://msdn.microsoft.com/en-us/library/vstudio/1k1skd40(v=vs.100).aspx
Upvotes: 0
Reputation: 28425
Timezone literals are not supported by DateTime.Parse/ParseExact. Here is a workaround:
string inputDate = "Tue Mar 18 14:37:34 PDT 2014";
inputDate = inputDate.Replace("PDT", "-7");
DateTime d = DateTime.ParseExact(inputDate, "ddd MMM dd HH:mm:ss z yyyy", culture);
Console.WriteLine(d);
Upvotes: 1