Reputation: 8400
on a developer machine (cassini)
new DateTime(2012,3,14).ToString("d")
results in
14/03/2012
which is correct but when deployed to a full IIS server the result is
03/14/2012
The server is set in control panel/Region language to all English/UK/GB, running date in command prompt returns the dd/MM/YYYY format.
The site is set for both uiCulture="en-GB"
and culture="en-GB"
and these show in the web.config globalization tag.
I can work around this issue by adding a forced culture
new DateTime(2012,3,14).ToString("d", new CultureInfo("en-GB"));
but I would really like to know what is setting the format incorrectly.
CultureInfo.CurrentCulture.Name, CultureInfo.CurrentUICulture.Name
both return en-US
M/d/yyyy
(e.g. 3/14/2012)dd/MM/yyyy
(e.g. 14/03/2012)Actual value in web.config
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8" uiCulture="en-GB" culture="en-GB" />
Upvotes: 24
Views: 66536
Reputation: 108975
In your web.config
add
<globalization culture='auto' uiCulture='auto' />
and then, assuming the browser is correctly configured to pass the preferred locale, the worker thread processing the request will have its CurrentCulture
and CurrentUICulture
set correctly.
Any locale dependent operations (including such things as DateTime
format d
) will use the client's preference.
Globalization element of web.config on MSDN: https://msdn.microsoft.com/en-us/library/ydkak5b9(v=vs.71).aspx
Upvotes: 5
Reputation: 40032
I managed to get it working by putting this into the web.config
<globalization culture="en-GB"/>
Upvotes: 31