Correct format for DateTime.ParseExact

I have the below string which I need to parse to a DateTime:

Thu Aug 14 2014 00:00:00 GMT 0100 (GMT Summer Time)

I am unsure what format to supply to my DateTime.ParseExact to achieve this. The nearest I could find in standard date/time format string was Full date/time pattern (long time) as below but this does not work

DateTime.ParseExact("Thu Aug 14 2014 00:00:00 GMT 0100 (GMT Summer Time)", "F", CultureInfo.InvariantCulture); // FormatException

Any ideas?

Jon Skeet
people
quotationmark

If the offset is not important, I suggest you just truncate the string after the time.

It looks like the format should allow that by finding the first space after position 16 (the start of the time in your example; part way through the time if the day number is shorter):

int endOfTime = text.IndexOf(' ', 16);
if (endOfTime == -1)
{
    throw new FormatException("Unexpected date/time format");
} 
text = text.Substring(0, endOfTime);
DateTime dateTime = DateTime.ParseExact(text, "ddd MMM d yyyy HH:mm:ss",
                                        CultureInfo.InvariantCulture);

(I'm assuming the month and day names are always in English.)

people

See more on this question at Stackoverflow