Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CultureInfo changes based on computer settings

I am running a .NET 5 MVC Web Application through IIS both on my local machine and a remote server.

I have noticed a strange bug where the computer's local settings appear to affect the result of the CultureInfo class

In Windows 10, if I open Settings > Time & Language > Region, and click Change data formats so that my Short time is 24 hour, i.e. 13:40 vs 1:40 PM, then the result of CultureInfo will also change. I had always assumed that changing my computer settings should not affect .NETs built in cultures, and that they should be the same no matter what computer the code runs on, so:

CultureInfo.CreateSpecificCulture("en-US");

Should return the same CultureInfo object no matter what computer the code is running on or what Date & Time settings the user decides to use.

I initially wondered if perhaps I was using the CultureInfo class wrong, so I also tried:

new CultureInfo("en-US");

But the results were the same.

Is there some way to tell the CultureInfo class to use the default values for the culture and not the use the settings that I currently have on my computer?

like image 589
Campbell Avatar asked Sep 03 '25 03:09

Campbell


1 Answers

var culture = new CultureInfo("en-US", false);

The second parameter of the constructor (useUserOverride) means exactly that.

  • true use the system settings
  • false use the default culture settings
like image 101
Kevin Verstraete Avatar answered Sep 06 '25 20:09

Kevin Verstraete