语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -4,7 +4,7 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-tolocalestring.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 class="syntaxbox"><var>dateObj.toLocaleString([locales [, options]])</var></pre>
<pre><code class="language-javascript"><var>dateObj.toLocaleString([locales [, options]])</var></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>查看<a href="#Browser_Compatibility" title="#Browser_Compatibility">浏览器兼容性</a>小节,看下哪些浏览器支持 <code style="font-style: normal;">locales</code> 和 <code style="font-style: normal;">options</code> 参数,还可以参看<a href="#Example:_Checking_for_support_for_locales_and_options_arguments">例子:检测 <code>locales</code><code>options</code> 参数支持情况</a></p>
<p></p><dl>
@@ -109,15 +109,15 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_toLocaleString" name="Example:_Using_toLocaleString">例子:使用 <code>toLocaleString</code></h3>
<p>没有指定语言环境locale返回一个使用默认语言环境和格式设置options的格式化字符串。</p>
<pre class="brush:js">var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));
<pre><code class="language-js">var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));
// toLocaleString 不包含参数的返回值取决于实现,
// 默认的区域(locale),和默认的时区(time zone)
date.toLocaleString();
// → 如果是在en-US区域和America/Los_Angeles时区运行返回值为"12/11/2012, 7:00:00 PM"</pre>
// → 如果是在en-US区域和America/Los_Angeles时区运行返回值为"12/11/2012, 7:00:00 PM"</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 style="font-style: normal;">locales</code> 和 <code style="font-style: normal;">options</code> 参数不是所有的浏览器都支持。为了检测一种实现环境implementation是否支持它们可以使用不合法的语言标签如果实现环境支持该参数则会抛出一个 <code style="font-style: normal;">RangeError</code> 异常,反之会忽略参数。</p>
<pre class="brush: js">function toLocaleStringSupportsLocales() {
<pre><code class="language-javascript">function toLocaleStringSupportsLocales() {
try {
new Date().toLocaleString("i");
} catch (e) {
@@ -125,10 +125,10 @@ date.toLocaleString();
}
return false;
}
</pre>
</code></pre>
<h3 id="Example:_Using_locales" name="Example:_Using_locales">例子:使用 <code>locales</code> 参数</h3>
<p>下例展示了本地化日期格式的一些变化。为了在应用的用户界面得到某种语言的日期和时间格式,必须确保使用 <code style="font-style: normal;">locales</code> 参数指定了该语言(可能还需要设置某些回退语言)。</p>
<pre class="brush: js">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
<pre><code class="language-javascript">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
//假定本地时区是 America/Los_Angeles(美国时区)
//en-US(美利坚英语)使用 month-day-year 的顺序展示年月日
@@ -156,10 +156,10 @@ alert(date.toLocaleString("ja-JP-u-ca-japanese"));
//那么将使用印尼语(id)
alert(date.toLocaleString(["ban", "id"]));
// → "20/12/2012 11.00.00"
</pre>
</code></pre>
<h3 id="Example:_Using_options" name="Example:_Using_options">例子:使用 <code>options</code> 参数</h3>
<p>可以使用 <code style="font-style: normal;">options </code>参数来自定义 <code style="font-style: normal;">toLocaleString</code> 方法返回的字符串。</p>
<pre class="brush: js">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
<pre><code class="language-javascript">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
//请求参数(options)中包含参数星期(weekday),并且该参数的值为长类型(long)
var options = {weekday: "long", year: "numeric", month: "long", day: "numeric"};
@@ -175,7 +175,7 @@ alert(date.toLocaleString("en-US", options));
// 使用24小时制
alert(date.toLocaleString("en-US", {hour12: false}));
// → "12/19/2012, 19:00:00"
</pre>
</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>