Campbell
Campbell

Reputation: 630

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?

Upvotes: 4

Views: 1486

Answers (1)

Kevin Verstraete
Kevin Verstraete

Reputation: 1463

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

Upvotes: 6

Related Questions