.WAFL (lØ@4@w«îPð“ȯeηùæntry(¯-åªm|— AâXè:Âé@w«îPð“ȯeηùæØrurl -http://www.honomichl.com/qa-date-format.htmlmime text/htmlhntt"25b63d-1de6-3ee0e4eb"hvrsdata W3C I18N Q&A: Non-English tags
W3C Architecture Domain International Home Page

Questions & Answers: Date formats

Question

How do I prepare my web pages to handle varying international date formats?

Background

Visitors to a web site from varying locales may be confused by date formats. The format MM/DD/YY is unique to the United States. Most of Europe uses DD/MM/YY. Japan uses YY/MM/DD. The separators may be slashes, dashes or periods. Some locales print leading zeroes, others suppress them. If a native Japanese speaker is reading a US English web page from a web site in Germany that contains the date 03/04/02 how do they interpret it?

Answer

Your first impulse may be to assume this problem will be taken care of during localization of the web pages - i.e. let the translator fix it. Resist this impulse. Do you really want to keep separate copies of documents for the U.S. and the U.K. that differ only in date format? In any case you still have to deal with multilingual users like the one in our example above.

You have two options to choose from. Both have some drawbacks.

Option One: Use a locale neutral format

ISO 8601 specifies a format of YYYY-MM-DD. 2003-04-02 is clearer than 03/04/02. Some prefer to modify ISO 8601 by using an abbreviation for the month to make it more clear, for example 2003-Apr-02.

Pros

Cons

Option Two: Use the Accept Language HTTP header

The HTTP Accept Language header only specifies the users language preferences, but is commonly used to determine locale preferences as well. This method works well for dynamically generated web docouments. How this is done will vary depending on your development environment. Here are some pointers for some common environments

Java/JSP

Call the getLocale method of the ServletRequest or HttpServletRequest object. Use the returned Locale object to call DateFormat. Note that the SHORT format uses only numbers. If you want unambiguous formats use FULL. In some locales even LONG is all numeric.Sample code.

ASP

Use Request.ServerVariables(ÒHTTP_ACCEPT_LANGUAGEÓ) to get the users preferences. Parse the first locale from the list of accepted locales. YouÕll have to do your own mapping from the alphabetic locale code to a numeric Locale Identifier. Set Session.LCID to the resulting value. Call FormatDateTime to format the date.

Use vbLongDate to avoid ambiguity.

Perl

Use $ENV {ÔHTTP_ACCEPT_LANGUAGEÕ} to get the preferred language. Use POSIX:strftime to format date values. YouÕll have to do your own mapping of the accepted languages value to a date format string.

Summary

No ideal solution exists for this problem. Weigh the options and choose according to your preferences and your situation.

Some have advocated the creation of a <date> tag that would display dates according the locale of the user agent. For example:

<DATE YEAR=2003 MONTH=4 DAY=2>

Other syntaxes have also been suggested. This approach has some complications as well.

Further information


Contributed by Lloyd Honomichl, Lionbridge.

Version: $Id: qa-date-format.html,v 1.3 2003/05/29 13:26:25 rishida Exp $

post@w«îXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXcate ¯-å@w«îL»•k»+€‘Øæcat @¯-å@w«îL»•k»+€‘Øæÿÿþaux 4SURL,http://www.honomichl.com/qa-date-format.html