<?php 
// authors should fill in these assignments:
$directory = 'questions/'; // the directory path below /International up to but not including the file name: must end in a slash! 
$filename = 'qa-date-format'; // the file name WITHOUT extensions
$authors = 'Lloyd Honomichl, Lionbridge'; // author(s) and affiliations
$modifiers = 'Richard Ishida, W3C'; // people making substantive changes, and their affiliation
$searchString = 'qa-date-format'; // blog search string - usually the filename without extensions
$firstPubDate = '2003-06-09'; // date of the first publication of the document (after review)
$lastSubstUpdate = '2007-07-04 18:23';  // date of last substantive changes to this document
$pathtophp = '../php'; // authors should check that the following points to /International/php - must be relative path

// authors AND translators should fill in these assignments:
$clang = 'en'; // the language extension for articles in this language (use 'en' for English)
$isTranslation = 'no';  // set to 'yes' if this is a translation !
$copyrightYear = '2003-2010'; // this year, but may also be a range, eg. 2002-2006
$thisVersion = '2010-09-07  19:19'; // date of latest edits to this document/translation

// translators should fill in these assignments:
$translators = 'xxxNAME, ORG'; // translator(s) and their affiliation - a elements allowed, but use double quotes for attributes
$enVersion = 'xxxYYYY-MM-DD';  // date of the English original on which the translation is based (see last substantive change date at bottom of file)

include($pathtophp.'/bp3/boilerplate-'.$clang.'.php');

if (! isset($s_articles)) { $s_articles = "Articles"; }
$breadcrumbs = <<<eot
<a href='/International/'>$s_home </a> &gt; <a href='/International/resources'>$s_resources</a> &gt; <a href='/International/articlelist#cultural'>$s_articles</a>
eot;

$toc = <<<eot
<ol>
<li><a href="#question">$s_questionLink</a></li>
<li><a href="#background">$s_backgroundLink</a></li>
<li><a href="#answer">$s_answerLink</a>
	<ol>
	<li><a href="#opt1">Option One: Use a locale neutral format</a></li>
	<li><a href="#opt2">Option Two: Make the month and year obvious</a></li>
	<li><a href="#opt3">Option Three: Use the Accept-Language HTTP header</a></li>
	<li><a href="#summary">Summary</a></li>
	</ol></li>
<li><a href="#bytheway">$s_byTheWayLink</a></li>
<li><a href="#endlinks">$s_furtherReadingLink</a></li>
</ol>
eot;

$additionalLinks = <<<eot
eot;
include($pathtophp.'/bp3/structure.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <?php echo "lang='$clang' xml:lang='$clang'";?> xmlns="http://www.w3.org/1999/xhtml">
<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Date formats</title>
		<meta name="keywords" content="i18n internationalisation internationalization localisation localization translation date format iso 8601" />
		<meta name="description" content="W3C I18N FAQ: How do I prepare my web pages to display varying international date formats?" />
<?php echo $headincludes;?>

<link rel="stylesheet" href="/International/style/article-standards-v2.css" type="text/css" />
</head>

	<body>
		<span id="version-info" style="display: none;"><!-- #BeginDate format:IS1m -->2010-09-07  19:28<!-- #EndDate --></span> <?php echo $topOfPage; ?>

		<h1>Date formats</h1>

		<div class="section"><a id="contentstart" name="contentstart"></a> 
			<div id="audience"> 
				<p><?php echo $intendedAudience?> 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.</p>
			<?php if ($outOfDateTranslation == 'yes') { echo "<p class='outofdate'>$s_untranslatedChanges </p>"; } ?>
			</div>

			<h2><?php echo $questionHead?></h2>
			<div class="section2"> 
				<p class="question">How do I prepare my web pages to display varying international date formats?</p>
			</div>
		</div>
		<p class="background-link noprint"><?php echo $skiptoAnswer?></p>
		<div class="section"> 

			<h2><?php echo $backgroundHead?></h2>
			<p>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?</p>
		</div>
		<div class="section"> 

			<h2><?php echo $answerHead?></h2>
			<p>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.</p>
			<p>You have three options to consider, all with advantages and drawbacks:</p>
			<ol>
				<li>Use a locale neutral format</li>
				<li>Make the month and year obvious</li>
				<li>Use the Accept-Language HTTP header</li>
			</ol>
			<div class="section2"> 

				<h3><a href="#opt1" name="opt1" id="opt1">Option One: Use a locale neutral format</a></h3>
				<p>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.). </p>
				<p><strong>Pros:</strong></p>
				<ul>
					<li>This method is unambiguous.</li>
					<li>ISO 8601 is computer friendly. Doing a standard character sort on a list of dates gives you a chronologically ordered list.</li>
				</ul>
				<p><strong>Cons:</strong></p>
				<ul>
					<li>ISO 8601 is people unfriendly. People are comfortable with their "natural" date formats.</li>
					<li>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.</li>
					<li>This may be particularly user unfriendly in countries where an alternative calendar is used (eg. Thailand favours the Buddhist
						calendar).</li>
				</ul>
			</div>
			<div class="section2"> 

				<h3><a href="#opt2" name="opt2" id="opt2">Option Two: Make the month and year obvious</a></h3>
				<p>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.</p>
				<p><strong>Pros:</strong></p>
				<ul>
					<li>This method is completely unambiguous.</li>
					<li>It is people friendly. People are comfortable with their "natural" date formats.</li>
				</ul>
				<p><strong>Cons:</strong></p>
				<ul>
					<li>It is less computer friendly when it comes to sorting, etc.</li>
					<li>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 <em>June</em> and <em>July</em> are the same, <em><span lang="fr" xml:lang="fr">juin</span></em> and <em><span xml:lang="fr"
						lang="fr">juillet</span></em>). Allowing extra space for this exacerbates the space problem.</li>
				</ul>
			</div>
			<div class="section2"> 

				<h3><a href="#opt3" name="opt3" id="opt3">Option Three: Use the Accept-Language HTTP header</a></h3>
				<p>The HTTP Accept-Language header only specifies the user's language preferences, but is commonly used to determine locale preferences
					as well.</p>
				<p>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. <a name="japanese-eg" id="japanese-eg">For example</a>:</p>
				<ul>
					<li>Inserting a date from a database into a <em>Japanese</em> page with a Japanese format would be very helpful for the user.</li>
					<li>A Japanese person reading the generated date 03/04/02 in an <em>English</em> document might mistakenly assume that this used an
						English ordering.</li>
					<li>Displaying a generated date in a Japanese date format such as <span lang="ja" xml:lang="ja">２００３年４月２日</span> in an English page
						would probably look out of place.</li>
				</ul>
				<p>How this is done will vary depending on your development environment. Here are some pointers for some common environments.</p>
				<div class="example"> 

					<h4>Java/JSP</h4>
					<p>Call the <code>getLocale</code> method of the <code>ServletRequest</code> or <code>HttpServletRequest</code> object. Use the
						returned <code>Locale</code> object to call <code>DateFormat</code>. Note that the SHORT format uses only numbers. If you want unambiguous formats
						use FULL. In some locales even LONG is all numeric. <!--(<a href="http://www.honomichl.com/java.html">Sample code</a>)--></p>
					<p>See also <a href="http://icu-project.org/">ICU4J</a>  since it contains   more up-to-date data (and more functionality) than the JDK routines.</p>
				</div>
				<div class="example"> 

					<h4>ASP</h4>
					<p>Use <code>Request.ServerVariables('HTTP_ACCEPT_LANGUAGE')</code> 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 <code>Session.LCID</code>
						to the resulting value. Call <code>FormatDateTime</code> to format the date.</p>
					<p>Use vbLongDate to avoid ambiguity.</p>
				</div>
				<div class="example"> 

					<h4>Perl</h4>
					<p>Use <code>$ENV{'HTTP_ACCEPT_LANGUAGE'}</code> to get the preferred language. Use <code>POSIX:strftime</code> to format date values.
						You'll have to do your own mapping of the accepted languages value to a date format string.</p>
				</div>
			</div>
			<div class="section2"> 

				<h3><a href="#summary" name="summary" id="summary">Summary</a></h3>
				<p>No ideal solution exists for this problem. Weigh the options and choose according to your preferences and your situation.</p>
				<p>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.</p>
				<p>Dates can be reformatted using dynamic techniques to match the linguistic context of the page.</p>
			</div>
		</div>
		<div class="section"> 

			<h2><?php echo $btwHead?></h2>
			<p>Some have advocated the creation of a &lt;date&gt; tag that would display dates according the locale of the user agent. This is subject
				to the same practical issues as described for dynamic date generation with the <a href="#japanese-eg">Japanese example</a>. The appropriate format is
				generally a function of the linguistic context of a page, rather than the user's platform.</p>
		</div>
<?php printf( $survey, $directory, $filename, $clang );?>
		<div class="section noprint"> 

			<h2><?php echo $readingHead?></h2>
			<ul id="full-links">
				<li> 
					<p><a href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html">ServletRequest API description, including
						getLocale method</a> <span class="uri">http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html</span></p>
				</li>
				<li> 
					<p><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html">Use of the Java DateFormat class</a> <span
						class="uri">http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html</span></p>
				</li>
				<li> 
					<p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctformatdatetime.asp">About VBScript
						FormatDateTime function</a> <span
						class="uri">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctformatdatetime.asp</span></p>
				</li>
				<li> 
					<p><a href="http://www.microsoft.com/globaldev/getWR/steps/wrg_date.mspx#web">Date formatting in the .NET Framework</a>
						<span class="uri">http://www.microsoft.com/globaldev/getWR/steps/wrg_date.mspx#web</span></p>
				</li>
				<li> 
					<p><a href="http://www.honomichl.com/java.html">Java/JSP sample code</a> <span
						class="uri">http://www.honomichl.com/java.html</span></p>
				</li>
			</ul>
		</div>
<?php echo $bottomOfPage; ?>

	</body>
</html>

