I have this date : 25/11/2019 14:20:17 CET I can't find a way to convert it to a datetime. Is there a generic way to convert properly several different date syntaxes?
try
{
mailMessage.MessageSentTime = DateTime.Parse(attValue);
}
catch
{
string[] formats = new[]
{
"ddd, dd MMM yyyy HH:mm:ss CEST",
"ddd, dd MMM yyyy HH:mm:ss CET",
"dd/mm/yyyy HH:mm:ss CET"
};
mailMessage.MessageSentTime = DateTime.ParseExact(attValue,
formats,
CultureInfo.InvariantCulture,
DateTimeStyles.None);
}
String '25/11/2019 14:20:17 CET' was not recognized as a valid DateTime.