This works:
DateTime.ParseExact(dtStr, "ddd MMM dd HH:mm:ss zzzz yyyy", CultureInfo.InvariantCulture)
ParseExact
and TryParseExact
allows to use a custom format string. ddd
is the abbreviated day name, MMM
the abbreviated month name, dd
the day number, HH
hours in 24h clock format, mm
minutes, ss
seconds, zzzz
the time-zone and yyyy
the years.
I have used CultureInfo.InvariantCulture
to specify that the current culture is not used but InvariantCulture
which is similar to "en-US"
.
Demo
works but after getting date from your line of code i tried to do
date.ToString("dd/mm/yyyy") but get the string as 12-12-2013, no
slashes
/
is a replacement character for your current culture's date-separator which is obviously -
. So also use CultureInfo.InvariantCulture
to specify that the separator should be used without using your current culture:
string result = dateTime.ToString("dd/mm/yyyy", CultureInfo.InvariantCulture);
See: The "/" Custom Format Specifier