I would like to convert the following string to DateTime
:
string start = "Wed Apr 27 2016 04:00:00 GMT+0300 (Jerusalem Daylight Time)";
I would like to convert the following string to DateTime
:
string start = "Wed Apr 27 2016 04:00:00 GMT+0300 (Jerusalem Daylight Time)";
Here you go:
string dateTimeString = "Wed Apr 27 2016 04:00:00 GMT+0300 (Jerusalem Daylight Time)";
string formatString = @"ddd MMM dd yyyy hh:mm:ss ""GMT""zzz ""(Jerusalem Daylight Time)""";
var parsedDateTime = DateTime.ParseExact(dateTimeString, formatString, System.Globalization.CultureInfo.InvariantCulture).ToLocalTime();
I stuck ToLocalTime()
on the end so there's less confusion about what timezone it returns. Anything between double-quotes is a literal, everything else is a DateTime Format Specifier. Note that zzz
is the UTC offset, not necessarily the GMT offset, but apparently GMT and UTC are effectively the same thing, so the code should be correct.