0

I have an MVC 4 application with international users (all over the world). I want to add a new page called profile settings where users can select their regional settings and by that I mean that they should be able to select:

  - time zone      (UTC +- .....)
  - date format    (dd.MM.yyyy or dd/MM/yyyy or MM/dd/yyyy ....)
  - time format    (12/24 - AM PM)
  - number format  (1234.56 or 1234,56)

After the user selects his regional settings, all specific data (date, time, number ...) should be shown in that specific format.

Any advice how to make this work?

David Dury
  • 5,537
  • 12
  • 56
  • 94

1 Answers1

0

Most of the time, you shouldn't expose each and every detail of the culture format to your users. Instead, provide a drop-down list of cultures you want to support. Cultures are specified using codes. Some common codes are en-US (English/USA), es-MX (Spanish/Mexico) and de-DE (Germany/German). The first part refers to the language, and the second part refers to the specific country or region.

Once you have the selected culture code, you can apply it to each user, such as:

CultureInfo culture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;

If you are using culture-specific resource files, then you will also need:

Thread.CurrentThread.CurrentUICulture = culture;

There are several places you could do this, but a common location is in the Application_BeginRequest event in your global.asax file.

There is a good tutorial on MSDN here.

While it is common to think about time zones when you are considering regional settings, they are actually quite different things and should be considered separately. Time zones can't really be set globally, you need to consider how they affect your application logic in each and every place you work with date and time. You should look into the TimeZoneInfo class. If you have questions, please ask separately. Although if you search, you may find that many have already been answered.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575