ASP.NET Globalization - Date Display

Good morning,

Apologies for the newbie question. I am just getting started with ASP.NET internationalization settings.

Background information:

I have a website that displays an <table>

HTML entity . In this <table>

HTML entity, I have a column that displays dates. My server is located in the USA, these dates are displayed as MM/DD/YYYY

. Many of my users connect to this web page via Excel via the Data -> Import External Data -> Import Web Query interface. Most of my users are in the United States, so these dates are displayed correctly on Excel screens.

Now I need to make a webpage for UK users. As is the case, they load dates as MM/DD/YYYY

, which makes their tables unusable since their locale is set to DD/MM/YYYY

.

My question is:

How do I do this so that the web server understands that the incoming request has a culture setting en-GB

? I could develop my own custom solution, but I'm sure I'm not the first programmer. How does he handle it? I'm looking for a solution that is relatively simple and quick to put up with, but I don't want to just put some shitty piece of my own logic that I will be afraid in 6 months.

Thanks a lot in advance, -Alan.

+1


source to share


3 answers


A few points:



  • The <globalization> element also needs a culture = "auto" attribute. The uiCulture attribute affects the language used to retrieve resources. The culture attribute affects the culture used to format numbers, dates.

  • As noted in this MSDN article , it is not recommended to exclusively use browser settings to define the UI culture for a page. Users often use browsers that are not tuned to their preferences (eg Internet cafes). You must provide a method that allows users to explicitly select the language, language, and culture (CultureInfo name) for the page.

+2


source


You can let the browser customize the UI culture automatically if you like by opening the web.config file, for example:

<configuration>
   <system.web>    
       <globalization uiCulture="auto" />
       ...

      



And then the culture set by the browser will be automatically installed in your application. This means that when you have the display date / time values ​​of the frame, they will be formatted according to the current UI culture.

This will also help if you are using currency and / or localized text (however, you must provide localized resources for each culture you support).

+2


source


You can also accept a query string parameter to override your culture settings.

The culture initialization should go in the Page.InitializeCulture method.

protected override void InitializeCulture ( )
{
  Thread.CurrentThread.CurrentCulture
    = Thread.CurrentThread.CurrentUICulture
    = Request.QueryString [ "culture" ] != null ? new CultureInfo ( Request.QueryString [ "culture" ] ) : CultureInfo.InvariantCulture;
  //base.InitializeCulture ( );
}

      

Usage: http://tempuri.org/page.aspx?culture=en-GB

+1


source







All Articles