mha.dk

Random thoughts of wisdom - the personal blog of Michael Holm Andersen

Use the 'Globalization' section in web.config

If you're from Denmark (like me!) chances are you would like all dates, numbers etc. formatted "the danish way" on your website. Instead of writing custom code on every page, you should instead tell ASP.NET which CultureInfo, Encoding etc. to use.

<configuration>
  <system.web>
    <globalization
       fileEncoding="utf-8"
       requestEncoding="utf-8"
       responseEncoding="utf-8"
       culture="da-DK"
       uiCulture="da-DK" /> 
  </system.web>
</configuration>

Values are valid if they are accepted by the related classes Encoding and CultureInfo. You can find more information about the Encoding and CultureInfo classes in the .NET Framework SDK.

A call to the method "ToShortDateString()" on a DateTime instance will now result in dd-mm-yyyy or e.g. 26-11-2006, which is nice.