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" />
If you already have it as a DateTime , use: string x = dt. ToString("yyyy-MM-dd");
I managed to get it working by putting this into the web.config
<globalization culture="en-GB"/>
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
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