Intended audience: XHTML/HTML coders (using editors or scripting), script developers (PHP, JSP, etc.), Web project managers, and anyone who wants to know how to handle international date formats.
How do I prepare my web pages to display varying international date formats?
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 (but sometimes used in Canada, too, which can obviously create some confusion there). 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?
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 three options to consider, all with advantages and drawbacks:
- Use a locale neutral format
- Make the month and year obvious
- Use the Accept-Language HTTP header
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, but then it is no longer locale neutral.).
- This method is unambiguous.
- ISO 8601 is computer friendly. Doing a standard character sort on a list of dates gives you a chronologically ordered list.
- ISO 8601 is people unfriendly. People are comfortable with their "natural" date formats.
- It takes more space. For a date in a paragraph of text this is no big deal. If a document is a table with some columns containing dates the extra space might become an issue, especially if you've designed a layout that is already pressed for space.
- This may be particularly user unfriendly in countries where an alternative calendar is used (eg. Thailand favours the Buddhist calendar).
Option Two: Make the month and year obvious
To do this use a name for the month (abbreviated or not) and use 4 digits for all Gregorian year numbers. For example, 2 April 2003.
- This method is completely unambiguous.
- It is people friendly. People are comfortable with their "natural" date formats.
- It is less computer friendly when it comes to sorting, etc.
- It takes more space. In some locales even the abbreviation for a month name may be longer than three characters. (In French the first three letters of June and July are the same, juin and juillet). Allowing extra space for this exacerbates the space problem.
Option Three: Use the Accept-Language HTTP header
The HTTP Accept-Language header only specifies the user's language preferences, but is commonly used to determine locale preferences as well.
This method works well for dynamically generated web documents when inserting a date from some back-end storage into a page, as long as the user's expectations of date format are clear. Appropriateness is a function of the linguistic context rather than simply the user's browser settings. For example:
- Inserting a date from a database into a Japanese page with a Japanese format would be very helpful for the user.
- A Japanese person reading the generated date 03/04/02 in an English document might mistakenly assume that this used an English ordering.
- Displaying a generated date in a Japanese date format such as ２００３年４月２日 in an English page would probably look out of place.
How this is done will vary depending on your development environment. Here are some pointers for some common environments.
Call the method of the or object. Use the returned object to call . Note that the SHORT format uses only numbers. If you want unambiguous formats use FULL. In some locales even LONG is all numeric.
See also ICU4J since it contains more up-to-date data (and more functionality) than the JDK routines.
Use to get the user's 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 to the resulting value. Call to format the date.
Use vbLongDate to avoid ambiguity.
Use to get the preferred language. Use to format date values. You'll have to do your own mapping of the accepted languages value to a date format string.
No ideal solution exists for this problem. Weigh the options and choose according to your preferences and your situation.
If there is likely to be any ambiguity on the part of the user, it is usually best to use explicit month names and 4-digit years for Gregorian dates, or at least indicate on the page how to read the dates.
Dates can be reformatted using dynamic techniques to match the linguistic context of the page.
Author's Last Name, First Initial. Middle Initial. (Year). Title of book. Place of Publication: Publisher.
Wegenstein, B. (2006). Getting under the skin: The body and media theory. Cambridge, MA: MIT Press.
Chapter Author's Last Name, First Initial. Middle Initial. (Year). Title of essay. In Editor First Initial. Middle Initial. Last Name (Ed.), Title of edited book (pp. Page Numbers of Chapter). Place of Publication: Publisher.
Tiggemann, M. (2002). Media influences on body image development. In T. F. Cash & T. Pruzinsky (Eds.), Body image: A handbook of theory, research, and clinical practice (pp. 91-98). New York, NY: Guilford Press.
Author's Last Name, First Initial. Middle Initial. (Year). Article title. Journal Title, Volume Number (Issue Number), Page Numbers. DOI
Schooler, D. (2008). Real women have curves: A longitudinal investigation of TV and the body image development of Latina adolescents. Journal of Adolescent Research, 23, 132-153. doi:10.1177/0743558407310712
Grabe, S., Ward, L. M., & Hyde, J. S. (2008). The role of the media in body image concerns among women: A meta-analysis of experimental and correlational studies. Psychological Bulletin, 134, 460-476. doi:10.1037/0033-2909.134.3.460
Author's Last Name, First Initial. Middle Initial. (Year, Month Day). Article title. Magazine Title, Volume Number, Page Numbers.
Underwood, N. (2001 August 14). Body envy. Maclean's, 113, 36-40.
Format: Varies depending on what type document it is. The basic citation format includes:
Organization or Author's Last Name, First Initial. Middle Initial. (Publication Year, Month Day) Title of document. Print Publication Information. Retrieved Month Day, Year, from URL
- If the source does not have a date of publication, use (n.d.).
- If the publication has no author, begin with the title and then the date.
American Psychological Association Task Force on the Sexualization of Girls. (2007). Report of the Task Force on the Sexualization of Girls. Washington, DC: Author. Retrieved April 12, 2008, from http:// www.apa.org/pi/wpo/sexualizationrep.pdf