Reputation: 485
I have a very odd one here.
In a simple Windows Form application i write the following C# Code
MessageBox.Show("Todays date is: "+DateTime.Today.ToShortDateString());
Running this normally just show the date in the format specified by windows (in the region settings). (so in my machine set to danish local it show the date as dd-MM-yyyy => 13-10-2017) This is expected.
But I have a customer's server (Windows Server 2012) where this is not the case. In their setup the Windows region settings is like mine (dd-MM-yyyy) but despite that the simple above code show it as MM/dd/yyyy => 10/13/2017 which is the American format.
I simply do not understand this and to make it even more of a mystery it is only for some windows users on this server (some show the format as the clock in window and other with the invariant format).
I've been searching on Google if there is some sort of .NET setting that can override on user-level but have not found anything.
There is nothing in the code that se culture and anything special (just File > New project > Winform [Targeting .net 4.5] and the line of code above ).
Upvotes: 2
Views: 1458
Reputation:
Have you tried using the ToString()
method?
DateTime.Today.ToString(CultureInfo.InvariantCulture)
Result: 10/13/2017 00:00:00
DateTime.Today.ToString(CultureInfo.CurrentCulture);
Result: 13.10.2017 00:00:00
This is what I experience on my (German) machine.
Upvotes: 1