One of my development applications has today started displaying American formatted short dates where I am expecting British formatting.
The dates are being rendered using date.ToShortDateString()
I have already checked my Regional settings, keyboard settings, browser settings and web.config. These are all set to English (UK) or not changed. I’ve also rebooted a number of times.
A mobile version of the same application, running from the same development server, and same website (different web application) is working correctly.
Environment:
- Windows 7 64 Bit
- Visual Studio 2010 Professional
- IIS 7.5
Where else can Regional Settings be changed that might influence display of dates?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The windows regional settings does not affect any website, unless the website is programmed to get the regional settings from the browser preferred languages and apply them to the ASP site
Use the globalization option in the web.config
<globalization culture="es-AR" uiCulture="es" />
OR
Set the value in the global.aspx Application_BeginRequest method
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim lang As String = "es"
If HttpContext.Current.Request.Path.Contains("/en/") Then
lang = "en"
ElseIf HttpContext.Current.Request.Path.Contains("/pt/") Then
lang = "pt"
ElseIf HttpContext.Current.Request.Path.Contains("/es/") Then
lang = "es"
End If
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
End Sub
Method 2
From MSDN
The value of the current DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.ShortDatePattern property associated with the current thread culture. The return value is identical to the value returned by specifying the “d” standard DateTime format string with the ToString(String) method.
Have you tried changing the culture for the current thread? This can be set on a per page basis as well – http://msdn.microsoft.com/en-us/library/bz9tc508%28v=vs.85%29.aspx.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0