I got a JSON on the server, and I try to parse it. The problem is that some dates looks like:
Tue, 03 Sep 2013 12:18:45 CEST
some as:
Sat, 17 Nov 2012 15:39:43 CET
so if I do somethins like:
var processedData = DateTime.ParseExact((string)item.pubDate, "ddd, dd MMM yyyy HH:mm:ss CEST", CultureInfo.InvariantCulture);
only on CEST dates it works, else it raises an exception.
How can I solve it? I hope .Replace() it is not the answer...
You can use Multiple Formats like:
string[] formats = new[]
{
"ddd, dd MMM yyyy HH:mm:ss CEST",
"ddd, dd MMM yyyy HH:mm:ss CET"
};
var processedData = DateTime.ParseExact((string)item.pubDate,
formats,
CultureInfo.InvariantCulture,
DateTimeStyles.None);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With