Internationalization Topics

Dates and Times in ICU

Dates

Different locales represent dates differently. Dates should be stored in a generic form in an internationalized application and formatted in the locale appropriate format just prior to being displayed to the user. ICU (International Components for Unicode) has a rich set of locale-based date formatting services. More information can be found at ICU Date Formatting. The following example illustrates how to format a short date for the fr_FR locale:

/* Parse a date with short French date/time formatter */
UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", "GMT", &status);
UErrorCode status = U_ZERO_ERROR;
int32_t parsepos=0;
UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos,
&status);

Often, non-internationalized applications include hard coded day and month names (i.e. "Sunday", "January", etc). If ICU date formatting is used, these can be removed altogether. ICU's locale-specific date formats correctly display the translated equivalents of days and month names.

Times

As with dates, times should be stored using a generic format throughout the internationalized source code. Times should be formatted according to the user's locale just prior to being displayed to the user. A general discussion of ICU's locale specific time formatting can be found at ICU Formatting Dates and Times Overview.

ICU also provides support for dealing with multiple time zones at ICU Time Zones.