I receive data containing a string of a datetime in the following format:
Tue Nov 08 11:20:00 GMT 2016
Fri Nov 11 08:05:00 GMT 2016
I'm finding it very difficult to parse this into a DateTime. How can this be parsed into a date time?
I think this should work:
public DateTime ConvertToDateTime(string dateString)
{
return DateTime.ParseExact(dateString, "ddd MMM dd HH:mm:ss Z yyyy", CultureInfo.InvariantCulture)
}
You can use DateTime.ParseExact
with a custom format string :
var dt = DateTime.ParseExact("Tue Nov 08 11:20:00 GMT 2016",
"ddd MMM dd HH:mm:ss Z yyyy", CultureInfo.InvariantCulture);
See this fiddle .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.