I inherited code like following:
System.DateTime dateTimeOut;
if(DateTime.TryParse("18/06/2015", out dateTimeOut))
{
Console.WriteLine("Good Job!");
}
"Good Job!" is never printed out. From MSDN I found that DateTime.TryParse
uses the DateTime format from System.Globalization.DateTimeFormatInfo.CurrentInfo
which in turn is from Thread.CurrentThread.CurrentCulture.DateTimeFormat
. And in my system it is "mm/dd/yyyy" - that's why "18/06/2015" cannot be parsed.
Then I went to Control Panel and changed DateTime format to "dd/mm/yyyy" and restarted my PC. But when I run the program again, Thread.CurrentThread.CurrentCulture.DateTimeFormat
is still "mm/dd/yyyy"....I am wondering who controls this setting and where I can change it?