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 swap to the "12/9/2014 10:09:28 PM"
Why did they swap day and month?
How they now where are day and where are a month?
They swap the month and date because in the US the date format is Month/Day/Year and in Great Britain (and most of the rest of the world) the data format is Day/Month/Year. So in the US "12/9/2014" is December, 9th 2014 and in GB it is September 12th, 2014.
That information is determined by CultureInfo.DateTimeFormat
.
This means that you cannot interpret a date string without knowing what culture it comes from.
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