I’m running a .NET Core app which contains DateTime.Now.ToString(). When on my PC it displays European date format (dd/mm/yy) but when running on a Linux VM located in the US it displays American date format (mm/dd/yy) despite the timezone on the VM being GMT.
How can I make it display only European date format?
I know I can format it manually inside the program, but is there a way to do this globally on the Linux system?
Advertisement
Answer
To set a culture for all application threads you can use CultureInfo.DefaultThreadCurrentCulture
property, like that
if (Thread.CurrentThread.CurrentCulture.Name == "en-US") { culture = CultureInfo.CreateSpecificCulture("..."); CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture; }
You are checking that current culture is en-US
and update the default culture to any EU specific culture, like de-DE
or fr-FR
for example. You can also refer to MSDN for details