How to parse a string before dateTime in C #?

string dateString = "12/9/2014 10:09:28 AM";
DateTime dateTime;

if (DateTime.TryParse(dateString, CultureInfo.GetCultureInfo("en-GB"),
    DateTimeStyles.AssumeUniversal, out dateTime))
{
   Console.WriteLine(dateTime); //"9/12/2014 10:09:28 PM";
}

When I do the same with "en-US", they change to "12/9/2014 10:09:28 PM"

Why did they change day and month?

How are they now, where is the day and where is the month?

+4
source share
2 answers

This is simply because each culture can have its own date and time designations. The interpretation depends on your culture, just like pants in trousers in the USA, but in underwear in the UK!

In en-GB culture, dates are recorded in the order of "day month year" and in en-US culture are dated in the order of "month day, year."

, CultureInfo.InvariantCulture ParseExact.

, TryParse, , . , en-US, > .

+5

, - //, ( ) - //. "12/9/2014" - 9 2014 , - 12 2014 .

CultureInfo.DateTimeFormat.

, , , .

+7

All Articles