Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime.ToString("d", cultureInfo) output differs between IIS and console app

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?

like image 489
Timo Avatar asked Jul 22 '16 09:07

Timo


1 Answers

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.

like image 197
Eli Arbel Avatar answered Oct 22 '22 13:10

Eli Arbel