I am using DateTime.Now.ToString("d", new CultureInfo("nl-NL"))
.
In a local IIS web application, the output is correct:
22-7-2016
In a console application, the framework chooses the international/culture-invariant date notation:
2016-07-22
This is on the same machine, with the exact same code. I have placed a breakpoint, checked all input, and even tried running the commands in the immediate window at that point. In every situation, the console application gets it wrong.
Can anybody explain what causes the difference?
IIS and your console app run under different user accounts. If you've customized the date format (e.g. by using the Region control panel), the CultureInfo
formatter will use that customization only in your account.
You can create a CultureInfo
that disregards user settings:
new CultureInfo("nl-NL", useUserOverride: false)
You reset the region settings for your account: Run > intl.cpl
> Select the NL locale in the drop-down > Additional settings > Reset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With