mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 23:44:06 +08:00
381 lines
31 KiB
HTML
381 lines
31 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<p><code><strong>toLocaleDateString()</strong></code> 方法返回该日期对象日期部分的字符串,该字符串格式因不同语言而不同。新增的参数 <code>locales</code> 和 <code>options</code> 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, <code>locales</code> 和 <code>options</code> 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。</p>
|
||
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-tolocaledatestring.html" width="100%"></iframe></div>
|
||
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
|
||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||
<pre><code class="language-javascript"><var>dateObj</var>.toLocaleDateString([locales [, options]])</code></pre>
|
||
<h3 id="Parameters" name="Parameters">参数</h3>
|
||
<p> 查看<a href="#Browser_Compatibility" title="#Browser_Compatibility">浏览器兼容性</a>小节,看下哪些浏览器支持 <code>locales</code> 和 <code>options</code> 参数,还可以参看<a href="#Example:_Checking_for_support_for_locales_and_options_arguments">例子: 检测 <code>locales</code> 和 <code>options</code> 参数支持情况</a>。</p>
|
||
<p></p><dl>
|
||
<dt><code>locales</code></dt>
|
||
<dd>
|
||
<p>Optional. A string with a BCP 47 language tag, or an array of such strings. Unicode extension are supported (for example <code>"en-US-u-ca-buddhist"</code>). For the general form and interpretation of the <code>locales</code> argument, see the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation" title="The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. The INTL object provides access to several constructors as well as functionality common to the internationalization constructors and other language sensitive functions.">Intl page</a>. The following Unicode extension keys are allowed:</p>
|
||
<dl>
|
||
<dt><code>nu</code></dt>
|
||
<dd>Numbering system. Possible values include: <code>"arab"</code>, <code>"arabext"</code>, <code>"bali"</code>, <code>"beng"</code>, <code>"deva"</code>, <code>"fullwide"</code>, <code>"gujr"</code>, <code>"guru"</code>, <code>"hanidec"</code>, <code>"khmr"</code>, <code>"knda"</code>, <code>"laoo"</code>, <code>"latn"</code>, <code>"limb"</code>, <code>"mlym"</code>, <code>"mong"</code>, <code>"mymr"</code>, <code>"orya"</code>, <code>"tamldec"</code>, <code>"telu"</code>, <code>"thai"</code>, <code>"tibt"</code>.</dd>
|
||
<dt><code>ca</code></dt>
|
||
<dd>Calendar. Possible values include: <code>"buddhist"</code>, <code>"chinese"</code>, <code>"coptic"</code>, <code>"ethioaa"</code>, <code>"ethiopic"</code>, <code>"gregory"</code>, <code>"hebrew"</code>, <code>"indian"</code>, <code>"islamic"</code>, <code>"islamicc"</code>, <code>"iso8601"</code>, <code>"japanese"</code>, <code>"persian"</code>, <code>"roc"</code>.</dd>
|
||
<dt><code>hc</code></dt>
|
||
<dd>Hour cycle. Possible values include: <code>"h11"</code>, <code>"h12"</code>, <code>"h23"</code>, <code>"h24"</code>.</dd>
|
||
</dl>
|
||
</dd>
|
||
<dt><code>options</code></dt>
|
||
<dd>
|
||
<p>Optional. An object with some or all of the following properties:</p>
|
||
<dl>
|
||
<dt><code>localeMatcher</code></dt>
|
||
<dd>The locale matching algorithm to use. Possible values are <code>"lookup"</code> and <code>"best fit"</code>; the default is <code>"best fit"</code>. For information about this option, see the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation" title="The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. The INTL object provides access to several constructors as well as functionality common to the internationalization constructors and other language sensitive functions.">Intl page</a>.</dd>
|
||
<dt><code>timeZone</code></dt>
|
||
<dd>The time zone to use. The only value implementations must recognize is <code>"UTC"</code>; the default is the runtime's default time zone. Implementations may also recognize the time zone names of the <a class="external" href="https://www.iana.org/time-zones" rel="noopener">IANA time zone database</a>, such as <code>"Asia/Shanghai"</code>, <code>"Asia/Kolkata"</code>, <code>"America/New_York"</code>.</dd>
|
||
<dt><code>hour12</code></dt>
|
||
<dd>Whether to use 12-hour time (as opposed to 24-hour time). Possible values are <code>true</code> and <code>false</code>; the default is locale dependent. This option overrides the <code>hc</code> language tag and/or the <code>hourCycle</code> option in case both are present.</dd>
|
||
<dt><code>hourCycle</code></dt>
|
||
<dd>The hour cycle to use. Possible values are <code>"h11"</code>, <code>"h12"</code>, <code>"h23"</code>, or <code>"h24"</code>. This option overrides the <code>hc</code> language tag, if both are present, and the <code>hour12</code> option takes precedence in case both options have been specified.</dd>
|
||
<dt><code>formatMatcher</code></dt>
|
||
<dd>The format matching algorithm to use. Possible values are <code>"basic"</code> and <code>"best fit"</code>; the default is <code>"best fit"</code>. See the following paragraphs for information about the use of this property.</dd>
|
||
</dl>
|
||
<p>The following properties describe the date-time components to use in formatted output, and their desired representations. Implementations are required to support at least the following subsets:</p>
|
||
<ul>
|
||
<li><code>weekday</code>, <code>year</code>, <code>month</code>, <code>day</code>, <code>hour</code>, <code>minute</code>, <code>second</code></li>
|
||
<li><code>weekday</code>, <code>year</code>, <code>month</code>, <code>day</code></li>
|
||
<li><code>year</code>, <code>month</code>, <code>day</code></li>
|
||
<li><code>year</code>, <code>month</code></li>
|
||
<li><code>month</code>, <code>day</code></li>
|
||
<li><code>hour</code>, <code>minute</code>, <code>second</code></li>
|
||
<li><code>hour</code>, <code>minute</code></li>
|
||
</ul>
|
||
<p>Implementations may support other subsets, and requests will be negotiated against all available subset-representation combinations to find the best match. Two algorithms are available for this negotiation and selected by the <code>formatMatcher</code> property: A <a class="external" href="http://www.ecma-international.org/ecma-402/1.0/#BasicFormatMatcher" rel="noopener">fully specified <code>"basic"</code> algorithm</a> and an implementation-dependent <code>"best fit"</code> algorithm.</p>
|
||
<dl>
|
||
<dt><code>weekday</code></dt>
|
||
<dd>The representation of the weekday. Possible values are:
|
||
<ul>
|
||
<li><code>"long"</code> (e.g., <code>Thursday</code>)</li>
|
||
<li><code>"short"</code> (e.g., <code>Thu</code>)</li>
|
||
<li><code>"narrow"</code> (e.g., <code>T</code>). Two weekdays may have the same narrow style for some locales (e.g. <code>Tuesday</code>'s narrow style is also <code>T</code>).</li>
|
||
</ul>
|
||
</dd>
|
||
<dt><code>era</code></dt>
|
||
<dd>The representation of the era. Possible values are:
|
||
<ul>
|
||
<li><code>"long"</code> (e.g., <code>Anno Domini</code>)</li>
|
||
<li><code>"short"</code> (e.g., <code>AD</code>)</li>
|
||
<li><code>"narrow"</code> (e.g., <code>A</code>)</li>
|
||
</ul>
|
||
</dd>
|
||
<dt><code>year</code></dt>
|
||
<dd>The representation of the year. Possible values are:
|
||
<ul>
|
||
<li><code>"numeric"</code> (e.g., <code>2012</code>)</li>
|
||
<li><code>"2-digit"</code> (e.g., <code>12</code>)</li>
|
||
</ul>
|
||
</dd>
|
||
<dt><code>month</code></dt>
|
||
<dd>The representation of the month. Possible values are:
|
||
<ul>
|
||
<li><code>"numeric"</code> (e.g., <code>2</code>)</li>
|
||
<li><code>"2-digit"</code> (e.g., <code>02</code>)</li>
|
||
<li><code>"long"</code> (e.g., <code>March</code>)</li>
|
||
<li><code>"short"</code> (e.g., <code>Mar</code>)</li>
|
||
<li><code>"narrow"</code> (e.g., <code>M</code>). Two months may have the same narrow style for some locales (e.g. <code>May</code>'s narrow style is also <code>M</code>).</li>
|
||
</ul>
|
||
</dd>
|
||
<dt><code>day</code></dt>
|
||
<dd>The representation of the day. Possible values are:
|
||
<ul>
|
||
<li><code>"numeric"</code> (e.g., <code>1</code>)</li>
|
||
<li><code>"2-digit"</code> (e.g., <code>01</code>)</li>
|
||
</ul>
|
||
</dd>
|
||
<dt><code>hour</code></dt>
|
||
<dd>The representation of the hour. Possible values are <code>"numeric"</code>, <code>"2-digit"</code>.</dd>
|
||
<dt><code>minute</code></dt>
|
||
<dd>The representation of the minute. Possible values are <code>"numeric"</code>, <code>"2-digit"</code>.</dd>
|
||
<dt><code>second</code></dt>
|
||
<dd>The representation of the second. Possible values are <code>"numeric"</code>, <code>"2-digit"</code>.</dd>
|
||
<dt><code>timeZoneName</code></dt>
|
||
<dd>The representation of the time zone name. Possible values are:
|
||
<ul>
|
||
<li><code>"long"</code> (e.g., <code>British Summer Time</code>)</li>
|
||
<li><code>"short"</code> (e.g., <code>GMT+1</code>)</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
</dd>
|
||
</dl><p></p>
|
||
<p>The default value for each date-time component property is <code>undefined</code>, but if the <code>weekday</code>, <code>year</code>, <code>month</code>, <code>day</code> properties are all <code>undefined</code>, then <code>year</code>, <code>month</code>, and <code>day</code> are assumed to be "numeric".</p>
|
||
<h2 id="Examples" name="Examples">例子</h2>
|
||
<h3 id="Example:_Using_toLocaleDateString" name="Example:_Using_toLocaleDateString">例子:使用<code>toLocaleDateString</code></h3>
|
||
<p>没有指定语言环境(locale)时,返回一个使用默认语言环境和格式设置(options)的格式化字符串。</p>
|
||
<pre><code class="language-js">var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));
|
||
|
||
// toLocaleDateString without arguments depends on the implementation,
|
||
// the default locale, and the default time zone
|
||
date.toLocaleDateString();
|
||
// → "12/11/2012" if run in en-US locale with time zone America/Los_Angeles</code></pre>
|
||
<h3 id="Example:_Checking_for_support_for_locales_and_options_arguments" name="Example:_Checking_for_support_for_locales_and_options_arguments">例子:检测 <code>locales</code> 和 <code>options</code> 参数支持情况</h3>
|
||
<p><code>locales</code> 和 <code>options</code> 参数不是所有的浏览器都支持。为了检测一种实现环境(implementation)是否支持它们,可以使用不合法的语言标签,如果实现环境支持该参数,则会抛出一个 <code>RangeError</code> 异常,反之会忽略参数。</p>
|
||
<pre><code class="language-javascript">function toLocaleDateStringSupportsLocales() {
|
||
try {
|
||
new Date().toLocaleDateString("i");
|
||
} catch (e) {
|
||
return e.name === "RangeError";
|
||
}
|
||
return false;
|
||
}
|
||
</code></pre>
|
||
<h3 id="Example:_Using_locales" name="Example:_Using_locales">例子:使用<code>locales</code></h3>
|
||
<p>下例展示了本地化日期格式的一些变化。为了在应用的用户界面得到某种语言的日期格式,必须确保使用 <code>locales</code> 参数指定了该语言(可能还需要设置某些回退语言)。</p>
|
||
<pre><code class="language-javascript">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
|
||
|
||
// formats below assume the local time zone of the locale;
|
||
// America/Los_Angeles for the US
|
||
|
||
// US English uses month-day-year order
|
||
alert(date.toLocaleDateString("en-US"));
|
||
// → "12/19/2012"
|
||
|
||
// British English uses day-month-year order
|
||
alert(date.toLocaleDateString("en-GB"));
|
||
// → "20/12/2012"
|
||
|
||
// Korean uses year-month-day order
|
||
alert(date.toLocaleDateString("ko-KR"));
|
||
// → "2012. 12. 20."
|
||
|
||
// Arabic in most Arabic speaking countries uses real Arabic digits
|
||
alert(date.toLocaleDateString("ar-EG"));
|
||
// → "<span dir="rtl">٢٠/١٢/٢٠١٢</span>"
|
||
|
||
// for Japanese, applications may want to use the Japanese calendar,
|
||
// where 2012 was the year 24 of the Heisei era
|
||
alert(date.toLocaleDateString("ja-JP-u-ca-japanese"));
|
||
// → "24/12/20"
|
||
|
||
// when requesting a language that may not be supported, such as
|
||
// Balinese, include a fallback language, in this case Indonesian
|
||
alert(date.toLocaleDateString(["ban", "id"]));
|
||
// → "20/12/2012"
|
||
</code></pre>
|
||
<h3 id="Example:_Using_options" name="Example:_Using_options">例子:使用<code>options</code></h3>
|
||
<p>可以使用 <code>options </code>参数来自定义 <code>toLocaleDateString</code> 方法返回的字符串。</p>
|
||
<pre><code class="language-javascript">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
|
||
|
||
// request a weekday along with a long date
|
||
var options = {weekday: "long", year: "numeric", month: "long", day: "numeric"};
|
||
alert(date.toLocaleDateString("de-DE", options));
|
||
// → "Donnerstag, 20. Dezember 2012"
|
||
|
||
// an application may want to use UTC and make that visible
|
||
options.timeZone = "UTC";
|
||
options.timeZoneName = "short";
|
||
alert(date.toLocaleDateString("en-US", options));
|
||
// → "Thursday, December 20, 2012, GMT"
|
||
</code></pre>
|
||
<h2 id="Performance" name="Performance">性能</h2>
|
||
<p>当格式化大量日期时,最好创建一个 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat" title="/en-US/docs/JavaScript/Reference/Global_Objects/DateTimeFormat"><code>Intl.DateTimeFormat</code></a> 对象,然后使用该对象 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format" title="/en-US/docs/JavaScript/Reference/Global_Objects/DateTimeFormat/format"><code>format</code></a> 属性提供的方法。</p>
|
||
<h2 id="规范">规范</h2>
|
||
<table class="standard-table">
|
||
<tbody>
|
||
<tr>
|
||
<th scope="col">规范版本</th>
|
||
<th scope="col">规范状态</th>
|
||
<th scope="col">注解</th>
|
||
</tr>
|
||
<tr>
|
||
<td>ECMAScript 3rd Edition. Implemented in JavaScript 1.0</td>
|
||
<td>Standard</td>
|
||
<td>Initial definition.</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://www.ecma-international.org/ecma-262/5.1/sec-15.9.5.6" hreflang="en" lang="en" rel="noopener">ECMAScript 5.1 (ECMA-262)<br/><small lang="zh-CN">Date.prototype.toLocaleDateString</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-date.prototype.tolocaledatestring" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Date.prototype.toLocaleDateString</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="http://www.ecma-international.org/ecma-402/1.0/#sec-13.3.2" rel="noopener">ECMAScript Internationalization API Specification, 1<sup>st</sup> Edition</a></td>
|
||
<td>Standard</td>
|
||
<td>Defines <code>locales</code> and <code>options</code> arguments.</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h2 id="浏览器兼容性">浏览器兼容性</h2>
|
||
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
|
||
<p></p><div class="bc-data"><a class="bc-github-link external" href="https://github.com/mdn/browser-compat-data" rel="noopener">Update compatibility data on GitHub</a><table class="bc-table bc-table-js"><thead><tr class="bc-platforms"><td></td><th class="bc-platform-desktop" colspan="6"><span>Desktop</span></th><th class="bc-platform-mobile" colspan="7"><span>Mobile</span></th><th class="bc-platform-server" colspan="1"><span>Server</span></th></tr><tr class="bc-browsers"><td></td><th class="bc-browser-chrome"><span class="bc-head-txt-label bc-head-icon-chrome">Chrome</span></th><th class="bc-browser-edge"><span class="bc-head-txt-label bc-head-icon-edge">Edge</span></th><th class="bc-browser-firefox"><span class="bc-head-txt-label bc-head-icon-firefox">Firefox</span></th><th class="bc-browser-ie"><span class="bc-head-txt-label bc-head-icon-ie">Internet Explorer</span></th><th class="bc-browser-opera"><span class="bc-head-txt-label bc-head-icon-opera">Opera</span></th><th class="bc-browser-safari"><span class="bc-head-txt-label bc-head-icon-safari">Safari</span></th><th class="bc-browser-webview_android"><span class="bc-head-txt-label bc-head-icon-webview_android">Android webview</span></th><th class="bc-browser-chrome_android"><span class="bc-head-txt-label bc-head-icon-chrome_android">Chrome for Android</span></th><th class="bc-browser-edge_mobile"><span class="bc-head-txt-label bc-head-icon-edge_mobile">Edge Mobile</span></th><th class="bc-browser-firefox_android"><span class="bc-head-txt-label bc-head-icon-firefox_android">Firefox for Android</span></th><th class="bc-browser-opera_android"><span class="bc-head-txt-label bc-head-icon-opera_android">Opera for Android</span></th><th class="bc-browser-safari_ios"><span class="bc-head-txt-label bc-head-icon-safari_ios">Safari on iOS</span></th><th class="bc-browser-samsunginternet_android"><span class="bc-head-txt-label bc-head-icon-samsunginternet_android">Samsung Internet</span></th><th class="bc-browser-nodejs"><span class="bc-head-txt-label bc-head-icon-nodejs">Node.js</span></th></tr></thead><tbody><tr><th scope="row"><code>toLocaleDateString</code></th><td class="bc-supports-yes bc-browser-chrome"><span class="bc-browser-name">Chrome</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-edge"><span class="bc-browser-name">Edge</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
12</td><td class="bc-supports-yes bc-browser-firefox"><span class="bc-browser-name">Firefox</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
1</td><td class="bc-supports-yes bc-browser-ie"><span class="bc-browser-name">IE</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-opera"><span class="bc-browser-name">Opera</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-safari"><span class="bc-browser-name">Safari</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-webview_android"><span class="bc-browser-name">WebView Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-chrome_android"><span class="bc-browser-name">Chrome Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-edge_mobile"><span class="bc-browser-name">Edge Mobile</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-firefox_android"><span class="bc-browser-name">Firefox Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
4</td><td class="bc-supports-yes bc-browser-opera_android"><span class="bc-browser-name">Opera Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-safari_ios"><span class="bc-browser-name">Safari iOS</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-yes bc-browser-samsunginternet_android"><span class="bc-browser-name">Samsung Internet Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-unknown bc-browser-nodejs"><span class="bc-browser-name">nodejs</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td></tr><tr><th scope="row"><code>locales</code></th><td class="bc-supports-yes bc-browser-chrome"><span class="bc-browser-name">Chrome</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
24</td><td class="bc-supports-yes bc-browser-edge"><span class="bc-browser-name">Edge</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
12</td><td class="bc-supports-yes bc-browser-firefox"><span class="bc-browser-name">Firefox</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
29</td><td class="bc-supports-yes bc-browser-ie"><span class="bc-browser-name">IE</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
11</td><td class="bc-supports-yes bc-browser-opera"><span class="bc-browser-name">Opera</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
15</td><td class="bc-supports-yes bc-browser-safari"><span class="bc-browser-name">Safari</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
10</td><td class="bc-supports-no bc-browser-webview_android"><span class="bc-browser-name">WebView Android</span><abbr class="bc-level-no only-icon" title="No support">
|
||
<span>No support</span>
|
||
</abbr>
|
||
No</td><td class="bc-supports-yes bc-browser-chrome_android"><span class="bc-browser-name">Chrome Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
26</td><td class="bc-supports-unknown bc-browser-edge_mobile"><span class="bc-browser-name">Edge Mobile</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-yes bc-browser-firefox_android"><span class="bc-browser-name">Firefox Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
56</td><td class="bc-supports-no bc-browser-opera_android"><span class="bc-browser-name">Opera Android</span><abbr class="bc-level-no only-icon" title="No support">
|
||
<span>No support</span>
|
||
</abbr>
|
||
No</td><td class="bc-supports-yes bc-browser-safari_ios"><span class="bc-browser-name">Safari iOS</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
10</td><td class="bc-supports-yes bc-browser-samsunginternet_android"><span class="bc-browser-name">Samsung Internet Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-unknown bc-browser-nodejs"><span class="bc-browser-name">nodejs</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td></tr><tr><th scope="row"><code>options</code></th><td class="bc-supports-yes bc-browser-chrome"><span class="bc-browser-name">Chrome</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
24</td><td class="bc-supports-yes bc-browser-edge"><span class="bc-browser-name">Edge</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
12</td><td class="bc-supports-yes bc-browser-firefox"><span class="bc-browser-name">Firefox</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
29</td><td class="bc-supports-yes bc-browser-ie"><span class="bc-browser-name">IE</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
11</td><td class="bc-supports-yes bc-browser-opera"><span class="bc-browser-name">Opera</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
15</td><td class="bc-supports-yes bc-browser-safari"><span class="bc-browser-name">Safari</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
10</td><td class="bc-supports-no bc-browser-webview_android"><span class="bc-browser-name">WebView Android</span><abbr class="bc-level-no only-icon" title="No support">
|
||
<span>No support</span>
|
||
</abbr>
|
||
No</td><td class="bc-supports-yes bc-browser-chrome_android"><span class="bc-browser-name">Chrome Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
26</td><td class="bc-supports-unknown bc-browser-edge_mobile"><span class="bc-browser-name">Edge Mobile</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-yes bc-browser-firefox_android"><span class="bc-browser-name">Firefox Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
56</td><td class="bc-supports-no bc-browser-opera_android"><span class="bc-browser-name">Opera Android</span><abbr class="bc-level-no only-icon" title="No support">
|
||
<span>No support</span>
|
||
</abbr>
|
||
No</td><td class="bc-supports-yes bc-browser-safari_ios"><span class="bc-browser-name">Safari iOS</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
10</td><td class="bc-supports-yes bc-browser-samsunginternet_android"><span class="bc-browser-name">Samsung Internet Android</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
Yes</td><td class="bc-supports-unknown bc-browser-nodejs"><span class="bc-browser-name">nodejs</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td></tr><tr><th scope="row">IANA time zone names in <code>timeZone</code> option</th><td class="bc-supports-yes bc-browser-chrome"><span class="bc-browser-name">Chrome</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
24</td><td class="bc-supports-yes bc-browser-edge"><span class="bc-browser-name">Edge</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
14</td><td class="bc-supports-yes bc-browser-firefox"><span class="bc-browser-name">Firefox</span><abbr class="bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
</abbr>
|
||
52</td><td class="bc-supports-unknown bc-browser-ie"><span class="bc-browser-name">IE</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-opera"><span class="bc-browser-name">Opera</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-safari"><span class="bc-browser-name">Safari</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-webview_android"><span class="bc-browser-name">WebView Android</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-chrome_android"><span class="bc-browser-name">Chrome Android</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-edge_mobile"><span class="bc-browser-name">Edge Mobile</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-no bc-browser-firefox_android"><span class="bc-browser-name">Firefox Android</span><abbr class="bc-level-no only-icon" title="No support">
|
||
<span>No support</span>
|
||
</abbr>
|
||
No</td><td class="bc-supports-unknown bc-browser-opera_android"><span class="bc-browser-name">Opera Android</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-safari_ios"><span class="bc-browser-name">Safari iOS</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-samsunginternet_android"><span class="bc-browser-name">Samsung Internet Android</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td><td class="bc-supports-unknown bc-browser-nodejs"><span class="bc-browser-name">nodejs</span><abbr title="Compatibility unknown; please update this.">
|
||
?
|
||
</abbr></td></tr></tbody></table><section class="bc-legend" id="sect1"><h3 class="offscreen" id="Legend">Legend</h3><dl><dt><span class="bc-supports-yes bc-supports">
|
||
<abbr class="bc-level bc-level-yes only-icon" title="Full support">
|
||
<span>Full support</span>
|
||
|
||
</abbr></span></dt><dd>Full support</dd><dt><span class="bc-supports-no bc-supports">
|
||
<abbr class="bc-level bc-level-no only-icon" title="No support">
|
||
<span>No support</span>
|
||
|
||
</abbr></span></dt><dd>No support</dd><dt><span class="bc-supports-unknown bc-supports">
|
||
<abbr class="bc-level bc-level-unknown only-icon" title="Compatibility unknown">
|
||
<span>Compatibility unknown</span>
|
||
|
||
</abbr></span></dt><dd>Compatibility unknown</dd></dl></section></div><p></p>
|
||
<h2 id="See_Also" name="See_Also">相关链接</h2>
|
||
<ul>
|
||
<li><a href="Reference/Global_Objects/DateTimeFormat" title="交互示例的源代码存储在 GitHub 资源库。如果你愿意分布交互示例,请复制https://github.com/mdn/interactive-examples,并向我们发送一个pull请求。"><code>DateTimeFormat</code></a></li>
|
||
<li><a href="Reference/Global_Objects/Date/toLocaleString" title="toLocaleString() 方法返回该日期对象的字符串,该字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。"><code>Date.prototype.toLocaleString()</code></a></li>
|
||
<li><a href="Reference/Global_Objects/Date/toLocaleTimeString" title="The toLocaleTimeString() 方法返回该日期对象时间部分的字符串,该字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。"><code>Date.prototype.toLocaleTimeString()</code></a></li>
|
||
</ul>
|
||
</article> |