DateTime and CultureInfo

petko_stankoski picture petko_stankoski · Dec 10, 2012 · Viewed 124.6k times · Source

I have this in my code:

var date1 = DateTime.ParseExact(date, "dd.MM.yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

And when my current cultur is dutch (nl-NL) instead of May 1st I get January 5th.

I think the error is in the second parameter dd.MM.yyyy HH:mm:ss.

Is there a way to fix this using the CultureInfo class?

Answer

MMK picture MMK · Dec 10, 2012

You may try the following:

System.Globalization.CultureInfo cultureinfo =
        new System.Globalization.CultureInfo("nl-NL");
DateTime dt = DateTime.Parse(date, cultureinfo);