How to parse CET/CEST datetime?
.net, c#, datetime, parsing
Solution
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);
Problem
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...