0

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?

Chaitanya
  • 1,698
  • 5
  • 21
  • 41
  • possible duplicate of [Parsing RFC1123 formatted dates in C#, .Net 4.0](http://stackoverflow.com/questions/2580356/parsing-rfc1123-formatted-dates-in-c-net-4-0) – Nathan Tuggy Apr 22 '15 at 01:28

2 Answers2

1

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);
Victor Hurdugaci
  • 28,177
  • 5
  • 87
  • 103
0

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

Josh Nester
  • 29
  • 1
  • 8