0

On one of my pages I display a datetime (from a database) and it is formatted correctly as a UK date time (dd-mm-yyyy) on my local machine. However when I deploy it to a server it reverts to American format (mm-dd-yyyy). Does anyone have any idea of when this might be happening?

This might be outside the scope of stackoverflow but I've check the server settings and everything seems to be set as UK in the regional settings.

Thanks

Jason Berkan
  • 8,734
  • 7
  • 29
  • 39
lancscoder
  • 8,658
  • 8
  • 48
  • 68

3 Answers3

11

This will be because the hosting/server is set to use american datetime when it was installed. unfortunately changing the settings now wont help .net.

you need to define the culture you wish to use in the webconfig:

<configuration>
   <system.web>
      <globalization culture="en-GB"/>
   </system.web>
</configuration>
JamesStuddart
  • 2,581
  • 3
  • 27
  • 45
  • Was facing a similar issue. Wasn't aware that changing the settings on the machine later wouldn't help. Weird! Thanks for the info though! – Vishal Shah Jun 01 '12 at 10:23
  • This might help someone. If you are using Local IIS the app pool identity/account is used! – dijam Mar 21 '17 at 11:24
6

You could set the UI culture in your web.config:

<globalization 
    requestEncoding="utf-8" 
    responseEncoding="utf-8" 
    culture="en-GB" 
    uiCulture="en-GB" />

or use the [DisplayFormat] attribute on a particular property of your view model:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-mm-yyyy}")]
public DateTime Date { get; set; }
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

You can set the culture in the web.config via the globalization tag.

E.g: <globalization culture="auto:en-GB" uiCulture="auto:en-GB">

Henryk
  • 1,119
  • 1
  • 10
  • 16