Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime and CultureInfo

Tags:

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?

like image 621
petko_stankoski Avatar asked Dec 10 '12 08:12

petko_stankoski


People also ask

What is CultureInfo in DateTime?

A DateTimeFormatInfo that defines the culturally appropriate format of displaying dates and times.

How to get DateTime culture in c#?

You can use date1. ToString(CultureInfo. CreateSpecificCulture("en-US")) .

What is the use of CultureInfo in C#?

The CultureInfo class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo objects.

What is System globalization CultureInfo Invariantculture?

The invariant culture is culture-insensitive; it is associated with the English language but not with any country/region. You specify the invariant culture by name by using an empty string ("") in the call to a CultureInfo instantiation method. CultureInfo.


1 Answers

You may try the following:

System.Globalization.CultureInfo cultureinfo =         new System.Globalization.CultureInfo("nl-NL"); DateTime dt = DateTime.Parse(date, cultureinfo); 
like image 135
MMK Avatar answered Oct 01 '22 23:10

MMK