.Net CurrentCulture ShortDateFormat doesn't update according to PC regional settings

466 views Asked by At

I'm configuring a new server and have been experiencing issues with parsing dates where the following code worked perfectly on the old server but not the new server.

IFormatProvider fpCanada = System.Globalization.CultureInfo.CreateSpecificCulture("en-CA");
Convert.ToDateTime(strStartDate, this.fpCanada); //en-CA

Error: System.FormatException: String was not recognized as a valid DateTime.

I don't want to have to modify the code to use TryParseExact or the registry, so my conclusion was to modify the PC's regional settings to match that of the old server.

Old server
Current format: English (Canada)
Short date: dd/MM/yyyy

New server
Current format: English (Canada)
Short date: yyyy-MM-DD

After updating the date format of the PC's regional settings to dd/MM/yyyy, I tried resetting the app pool, but that doesn't seem to have done anything.

// Still returns yyyy-MM-dd
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern 

Am I wrong in assuming that the PC's regional settings have a direct correlation to the ShortDatePattern in .Net?

1

There are 1 answers

0
MPaul On

PC Regional and Language Settings are being ignored in .Net

I suspect you are running the application under an identity without its own profile, and it is using the default regional settings stored in the registry under 'HKEY_USERS.Default\Control Panel\International`.