Why date format changes itself when change the browser? Why date format changes itself when change the browser? asp.net asp.net

Why date format changes itself when change the browser?


I can't test it right now, but I guess the IE is sending a "Accept-Language" header in the request, that is different of your current culture. Thus, it is overriding the current culture of the application (Culture of the WebServer/IIS)...

Try to set this on your Web.config:

 <configuration>    <system.web>       <globalization culture="en-GB" uiCulture="en-GB" />    </system.web> </configuration>

Set your desired culture inside the principal key. (But the culture "en-GB" already provides the desired date format).

Hope I helped...


If you want to override the culture so that the format is always 'dd/MM/yyyy' then you can use the following.

Convert.ToDateTime(Eval("Leave_To")).ToString("dd/MM/yyyy", DateTimeFormatInfo.InvariantInfo)


It looks like you want to force the delimiters to be a specific character (i.e., a '/' character) instead of what the default culture provides. This is easily accomplished by hard-coding the delimiters as literals in your date formatting string, to wit:

foo.ToString("dd'/'MM'/'yyyy")

Note the addition of quote marks surrounding the '/' delimiter characters.