3

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?

Mark Cooper
  • 6,738
  • 5
  • 54
  • 92

2 Answers2

5

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
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206
  • This has worked, but I think this is fixing the symptom rather than the cause. Other applications are correctly picking up en-GB without having this value set. – Mark Cooper Nov 16 '12 at 07:57
  • @MarkCooper: it depends on the default configuration of the server or application pool – Eduardo Molteni Nov 16 '12 at 12:12
  • So these are the settings I'm looking for. My "server" is a WIN7 developer VM, so those settings are defined in Region and Language. Where is the app-pool culture defined? – Mark Cooper Nov 16 '12 at 13:00
  • IIS get Invariant Culture if none is specified (Who uses american formats), but maybe you (or the others) are using Cassini o IIS Express as web server – Eduardo Molteni Nov 16 '12 at 16:33
1

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.

Kami
  • 19,134
  • 4
  • 51
  • 63