- From: Richard Ishida <ishida@w3.org>
- Date: Wed, 28 May 2003 19:04:10 +0100
- To: <public-i18n-geo@w3.org>
From: Lloyd Honomichl [mailto:lloyd@honomichl.com] Sent: 26 May 2003 17:11 To: ishida@w3.org Subject: Re: This week's Q&A Sorry about the delay. I missed the last call due to the arrival of grandchild number 2. Besides, I should get some extra slack since today is a holiday in the U.S. - Memorial Day. In any case here's my Q&A: Question: How do I handle date formatting in my web pages? Answer: For static web pages there is no ideal solution. It would be nice if there was some sort of <DATE> tag that would display dates according the locale of the user agent, but no such tag exists. It is common to change date formats during localization of the pages, but this is not a complete solution. English is spoken in both the U.S. and the U.K. but they use different date formats, so the language of the document is not sufficient to determine the format for dates. Multi-lingual users may potentially be confused by date formats as well. If a native Japanese speaker is reading an English web page from a web site in Germany that contains the date 03/04/02 how will they react? In such cases, it is important to use an unambiguous format. Using ISO 8601 is one approach. 2003-04-02 is somewhat clearer than 03/04/02. Using an abbreviation for the month makes it even more clear: 2003-Apr-02. For dynamically generated web pages you can use the HTTP_ACCEPT_LANGUAGE header to control which date format is used. A full discussion of how to do this would be too large for this document, but here are 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. 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. 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 langauges value to a date format string. Remember, even if you use one of these methods for formatting the date, choose an unambiguous date format to avoid the sort of problems mentioned above. For Java avoid the SHORT format, which uses only numbers. For ASP use vbLongDate. References: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ ServletRequest.html http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ script56/html/vsfctformatdatetime.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ iisref/htm/internationalclients.asp On Friday, May 23, 2003, at 01:39 AM, Richard Ishida wrote: > Hi Lloyd, > > I think you were due to submit a question this week for review by > email. > Do you have something ready? > > Cheers, > RI > > ============ > Richard Ishida > W3C > > tel: +44 1753 480 292 > http://www.w3.org/International/ http://www.w3.org/People/Ishida/ > > >
Received on Wednesday, 28 May 2003 14:04:14 UTC