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

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

@@ -2,8 +2,8 @@
<div></div>
<p><code><strong>[@@toPrimitive]()</strong></code> 方法可以转换一个 <code>Date</code> 对象到一个原始值。</p>
<h2 id="用法">用法</h2>
<pre class="syntaxbox"><var>Date()[Symbol.toPrimitive](hint);
</var></pre>
<pre><code class="language-javascript"><var>Date()[Symbol.toPrimitive](hint);
</var></code></pre>
<h3 id="返回值">返回值</h3>
<p>给出的 <a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 的原始值。根据传入参数的不同,可以返回 string 或 number 类型。</p>
<h2 id="说明">说明</h2>

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-utc.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"><code>Date.UTC(<em>year</em>,<em>month</em>[,<em>date</em>[,<em>hrs</em>[,<em>min</em>[,<em>sec</em>[,<em>ms</em>]]]]]) </code></pre>
<pre><code class="language-javascript"><code>Date.UTC(<em>year</em>,<em>month</em>[,<em>date</em>[,<em>hrs</em>[,<em>min</em>[,<em>sec</em>[,<em>ms</em>]]]]]) </code></code></pre>
<h2 id="Parameters" name="Parameters">参数</h2>
<dl>
<dt><code>year</code></dt>
@@ -35,8 +35,8 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_Date.UTC" name="Example:_Using_Date.UTC">例子:使用 <code>Date.UTC</code></h3>
<p>下面的语句使用 UTC 时间代替本地时间创建了一个日期对象。</p>
<pre class="brush:js">var utcDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0));
</pre>
<pre><code class="language-js">var utcDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0));
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-getdate.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 language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getDate()</code></pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getDate()</code></code></pre>
<h2 id="Parameters" name="Parameters">参数</h2>
<p></p>
<h2 id="Description" name="Description">描述</h2>
@@ -12,10 +12,10 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getDate" name="Example:_Using_getDate">例子: 使用getDate()<code>方法</code></h3>
<p>下面第二条语句将值25赋给 day 变量,该值<span style="line-height: 1.5;">基于日期对象 </span><code style="font-style: normal; line-height: 1.5;">Xmax95</code><span style="line-height: 1.5;">的值。</span></p>
<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<pre><code class="language-js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="keyword token" style="color: #0077aa;">var</span> day <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getDate<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>day<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 25</span></code></pre>
<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>day<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 25</span></code></code></pre>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>

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-getday.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 language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getDay()</code></pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getDay()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Description" name="Description">返回值</h3>
@@ -12,10 +12,10 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getDay" name="Example:_Using_getDay">例子:使用<code>getDay</code>方法</h3>
<p>下面第二条语句,基于日期对象 <code>Xmas95</code> 的值,把 1 赋值给 <code>weekday</code>。也就是说1995年12月25日是星期一。</p>
<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<pre><code class="language-js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="keyword token" style="color: #0077aa;">var</span> weekday <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getDay<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>weekday<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 1</span></code></pre>
<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>weekday<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 1</span></code></code></pre>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -6,7 +6,7 @@
<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 style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getFullYear()</code>
</pre>
</code></pre>
<h3 id="Description" name="Description">返回值</h3>
<p>根据当地时间,返回一个对应于给定日期的年份数字。</p>
<h2 id="描述">描述</h2>
@@ -14,9 +14,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getFullYear" name="Example:_Using_getFullYear">使用<code>getFullYear()</code></h3>
<p>下面的例子将当前年份的四位数值分配给变量<code>year</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var year = today.getFullYear();
</pre>
</code></pre>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>

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-gethours.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="语法">语法</h2>
<pre class="syntaxbox language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><var>dateObj</var>.getHours()</pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><var>dateObj</var>.getHours()</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Description" name="Description">返回值</h3>
@@ -12,10 +12,10 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getHours" name="Example:_Using_getHours">例子:使用<code>getHours</code>方法</h3>
<p>下面第二条语句,基于日期对象 <code>Xmas95 </code>的值,把 23 赋值给了变量 <code>hours。</code></p>
<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<pre><code class="language-js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="keyword token" style="color: #0077aa;">var</span> hours <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getHours<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>hours<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 23</span></code></pre>
<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>hours<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 23</span></code></code></pre>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>

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-getmilliseconds.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 language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><var>dateObj</var>.getMilliseconds()</pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><var>dateObj</var>.getMilliseconds()</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Description" name="Description">描述</h3>
@@ -12,9 +12,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getMilliseconds" name="Example:_Using_getMilliseconds">例子:使用<code>getMilliseconds</code>方法</h3>
<p>下例中,将当前时间的毫秒数赋值给变量 <code>ms</code></p>
<pre class="brush: js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> ms<span class="punctuation token" style="color: #999999;">;</span>
<pre><code class="language-js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> ms<span class="punctuation token" style="color: #999999;">;</span>
Today <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
ms <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Today<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getMilliseconds<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre>
ms <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Today<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getMilliseconds<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></code></pre>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,7 +3,7 @@
<p><strong><code>getMinutes()</code></strong> 方法根据本地时间,返回一个指定的日期对象的分钟数。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-getminutes.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getMinutes()</code></pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getMinutes()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Description" name="Description">描述</h3>
@@ -11,8 +11,8 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getMinutes" name="Example:_Using_getMinutes">例子:使用<code>getMinutes方法</code></h3>
<p>下例中,第二行语句运行过后,变量 <code>minutes </code>的值为15也就是说 <code>Xmas95 </code>这个日期对象的值为某时15分某秒。</p>
<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="keyword token" style="color: #0077aa;">var</span> minutes <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getMinutes<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre>
<pre><code class="language-js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="keyword token" style="color: #0077aa;">var</span> minutes <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getMinutes<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></code></pre>
<p dir="ltr"><strong style="font-size: 2.142857142857143rem; font-weight: 700; letter-spacing: -1px; line-height: 30px;">规范</strong></p>
<table class="standard-table">
<tbody>

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-getmonth.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 language-html">dateObj.getMonth()</pre>
<pre><code class="language-html">dateObj.getMonth()</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Description" name="Description">返回值</h3>
@@ -12,10 +12,10 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getMonth" name="Example:_Using_getMonth">使用 <code>getMonth()</code></h3>
<p>下面第二条语句,基于 <a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 对象 Xmas95 的值把11赋值给变量 <code>month。</code></p>
<pre class="brush:js language-js">var Xmas95 = new Date('December 25, 1995 23:15:30');
<pre><code class="language-js language-js">var Xmas95 = new Date('December 25, 1995 23:15:30');
var month = Xmas95.getMonth();
console.log(month); // 11</pre>
console.log(month); // 11</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-getseconds.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 language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getSeconds()</code></pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getSeconds()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Description" name="Description">描述</h3>
@@ -12,8 +12,8 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getSeconds" name="Example:_Using_getSeconds">例子: 使用<code>getSeconds方法</code></h3>
<p>下面第二条语句,基于日期对象 <code>Xmas95</code> 的值,把 30 赋值给变量 <code>secs</code></p>
<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:30"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="keyword token" style="color: #0077aa;">var</span> secs <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getSeconds<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre>
<pre><code class="language-js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:30"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
<span class="keyword token" style="color: #0077aa;">var</span> secs <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getSeconds<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></code></pre>
<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 0px; background: transparent;"> </div>
<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 19px; background: transparent;"> </div>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>

View File

@@ -5,7 +5,7 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-gettime.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"><code>dateObj.getTime() </code></pre>
<pre><code class="language-javascript"><code>dateObj.getTime() </code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Description" name="Description">返回值</h3>
@@ -13,13 +13,13 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="使用_getTime()_复制日期对象">使用 getTime() 复制日期对象</h3>
<p>创建一个拥有相同时间值的日期对象。</p>
<pre class="brush: js">var birthday = new Date(1991, 9, 17);
<pre><code class="language-javascript">var birthday = new Date(1991, 9, 17);
var copy = new Date();
copy.setTime(birthday.getTime());
</pre>
</code></pre>
<h3 id="测量代码执行时间">测量代码执行时间</h3>
<p>连续调用两个新生成的日期对象的 getTime 方法,根据两次调用的返回值求得时间差。这可以用于计算某些操作的执行时间。避免生成不必要的<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a>对象另见<a href="Reference/Global_Objects/Date/now" title="Date.now() 方法返回自1970年1月1日 00:00:00 UTC到当前时间的毫秒数。"><code>Date.now()</code></a> </p>
<pre class="brush:js">var end, start, i;
<pre><code class="language-js">var end, start, i;
start = new Date();
for (i = 0; i &lt; 1000; i++) {
@@ -27,7 +27,7 @@ for (i = 0; i &lt; 1000; i++) {
}
end = new Date();
console.log("Operation took " + (end.getTime() - start.getTime()) + " msec");</pre>
console.log("Operation took " + (end.getTime() - start.getTime()) + " msec");</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,16 +4,16 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-gettimezoneoffset.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 language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getTimezoneOffset()</code></pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getTimezoneOffset()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Description" name="Description">返回值</h3>
<p>时区偏差time-zone offset表示协调世界时UTC与本地时区之间的差值单位为分钟。需要注意的是如果本地时区晚于协调世界时则该差值为正值如果早于协调世界时则为负值。例如你所在时区为 UTC+10澳大利亚东部标准时间将会返回 -600。对于同一个时区夏令时Daylight Saving Time将会改变这个值。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getTimezoneOffset" name="Example:_Using_getTimezoneOffset">例子: 使用<code>getTimezoneOffset方法</code></h3>
<pre class="brush:js">var x = new Date();
<pre><code class="language-js">var x = new Date();
var currentTimeZoneOffsetInHours = x.getTimezoneOffset() / 60;
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,7 +3,7 @@
<p><strong><code>getUTCDate()</code></strong> 方法以世界时为标准,返回一个指定的日期对象为一个月中的第几天</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-getutcdate.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.getUTCDate()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCDate()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -11,9 +11,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCDate" name="Example:_Using_getUTCDate">例子: 使用 <code>getUTCDate()</code> 方法</h3>
<p>下面的例子是把当前日期的天数部分赋值给变量 <code>day</code>.</p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var day = today.getUTCDate();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-getutcday.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"><code><var>dateObj</var>.getUTCDay()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCDay()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -12,9 +12,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCDay" name="Example:_Using_getUTCDay">例子: 使用 <code>getUTCDay()</code> 方法</h3>
<p>下面的例子是把当前日期的星期部分赋值给变量 <code>weekday</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var weekday = today.getUTCDay();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-getutcfullyear.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"><code><var>dateObj</var>.getUTCFullYear()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCFullYear()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -12,9 +12,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCFullYear" name="Example:_Using_getUTCFullYear">例子: 使用 <code>getUTCFullYear()</code> 方法</h3>
<p>下面的例子是把当前年份的四位数值复制给变量 <code>year</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var year = today.getUTCFullYear();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-getutchours.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"><code><var>dateObj</var>.getUTCHours()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCHours()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -12,9 +12,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCHours" name="Example:_Using_getUTCHours">例子: 使用 <code>getUTCHours()</code> 方法</h3>
<p>下例将当前时间的小时部分赋值给变量 <code>hours</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var hours = today.getUTCHours();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,7 +3,7 @@
<p><strong><code>getUTCMilliseconds()</code></strong> 方法以世界时为标准,返回一个指定的日期对象的毫秒数。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-getutcmilliseconds.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.getUTCMilliseconds()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCMilliseconds()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -11,9 +11,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCMilliseconds" name="Example:_Using_getUTCMilliseconds">例子: 使用 <code>getUTCMilliseconds()</code> 方法</h3>
<p>下例将当前时间的毫秒部分赋值给变量 <code>milliseconds</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var milliseconds = today.getUTCMilliseconds();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,7 +3,7 @@
<p><strong><code>getUTCMinutes()</code></strong> 方法以世界时为标准,返回一个指定的日期对象的分钟数。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-getutcminutes.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.getUTCMinutes()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCMinutes()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -11,9 +11,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCMinutes" name="Example:_Using_getUTCMinutes">例子: 使用 <code>getUTCMinutes()</code> 方法</h3>
<p>下例将当前时间的分钟部分赋值给变量 <code>minutes</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var minutes = today.getUTCMinutes();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-getutcmonth.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"><code><var>dateObj</var>.getUTCMonth()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCMonth()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -12,9 +12,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCMonth" name="Example:_Using_getUTCMonth">例子: 使用 <code>getUTCMonth()</code> 方法</h3>
<p>下例将当前时间的月份赋值给变量 <code>month</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var month = today.getUTCMonth();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,7 +3,7 @@
<p><strong><code>getUTCSeconds()</code></strong> 方法以世界时为标准,返回一个指定的日期对象的秒数。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-getutcseconds.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.getUTCSeconds()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.getUTCSeconds()</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p>无。</p>
<h3 id="Returns" name="Returns">返回值</h3>
@@ -11,9 +11,9 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_getUTCSeconds" name="Example:_Using_getUTCSeconds">例子: 使用 <code>getUTCSeconds()</code> 方法</h3>
<p>下例将当前时间的秒数部分赋值给变量 <code>seconds</code></p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var seconds = today.getUTCSeconds();
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,7 +4,7 @@
</div></div>
<p>getYear() 方法返回指定的本地日期的年份。因为 <code>getYear</code> 不返回千禧年[full years] ("year 2000 problem"),所以这个方法不再被使用,现在替换为 <a href="Reference/Global_Objects/Date/getFullYear" title="getFullYear() 方法根据本地时间返回指定日期的年份。"><code>getFullYear</code></a> .</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox"><code>dateObj.getYear() </code></pre>
<pre><code class="language-javascript"><code>dateObj.getYear() </code></code></pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>None.</p>
<h3 id="Description" name="Description">Returns</h3>
@@ -25,24 +25,24 @@
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example:_Years_between_1900_and_1999" name="Example:_Years_between_1900_and_1999">Example: Years between 1900 and 1999</h3>
<p>The second statement assigns the value 95 to the variable <code>year</code>.</p>
<pre class="brush:js">var Xmas = new Date("December 25, 1995 23:15:00");
<pre><code class="language-js">var Xmas = new Date("December 25, 1995 23:15:00");
var year = Xmas.getYear(); // returns 95
</pre>
</code></pre>
<h3 id="Example:_Years_above_1999" name="Example:_Years_above_1999">Example: Years above 1999</h3>
<p>The second statement assigns the value 100 to the variable <code>year</code>.</p>
<pre class="brush:js">var Xmas = new Date("December 25, 2000 23:15:00");
<pre><code class="language-js">var Xmas = new Date("December 25, 2000 23:15:00");
var year = Xmas.getYear(); // returns 100
</pre>
</code></pre>
<h3 id="Example:_Years_below_1900" name="Example:_Years_below_1900">Example: Years below 1900</h3>
<p>The second statement assigns the value -100 to the variable <code>year</code>.</p>
<pre class="brush:js">var Xmas = new Date("December 25, 1800 23:15:00");
<pre><code class="language-js">var Xmas = new Date("December 25, 1800 23:15:00");
var year = Xmas.getYear(); // returns -100
</pre>
</code></pre>
<h3 id="Example:_Setting_and_getting_a_year_between_1900_and_1999" name="Example:_Setting_and_getting_a_year_between_1900_and_1999">Example: Setting and getting a year between 1900 and 1999</h3>
<p>The second statement assigns the value 95 to the variable <code>year</code>, representing the year 1995.</p>
<pre class="brush:js">var Xmas.setYear(95);
<pre><code class="language-js">var Xmas.setYear(95);
var year = Xmas.getYear(); // returns 95
</pre>
</code></pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,8 +3,8 @@
<p><strong><code>Date.now()</code></strong> 方法返回自1970年1月1日 00:00:00 UTC到当前时间的毫秒数。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-now.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox">var timeInMs = Date.now();
</pre>
<pre><code class="language-javascript">var timeInMs = Date.now();
</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h2 id="Description" name="Description">描述</h2>
@@ -12,12 +12,12 @@
<p>因为 now() 是<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a>的一个静态函数,所以必须以 Date.now() 的形式来使用。</p>
<h2 id="Compatibility" name="Compatibility">兼容旧环境</h2>
<p>该方法在 ECMA-262 第五版中被标准化,可以通过下面的代码来兼容那些不支持该方法的引擎。</p>
<pre class="brush: js">if (!Date.now) {
<pre><code class="language-javascript">if (!Date.now) {
Date.now = function now() {
return <code>new Date().getTime()</code>;
};
}
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -6,10 +6,10 @@
<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>
<p>显式调用:</p>
<pre class="syntaxbox"><code>Date.parse(dateString)</code></pre>
<pre><code class="language-javascript"><code>Date.parse(dateString)</code></code></pre>
<p><code>隐式调用:</code></p>
<pre class="syntaxbox"><code>new Date(<var>dateString</var>)</code>
</pre>
<pre><code class="language-javascript"><code>new Date(<var>dateString</var>)</code>
</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>dateString</code></dt>
@@ -33,42 +33,42 @@
<h3 id="引擎相关的日期格式">引擎相关的日期格式</h3>
<p>ECMAScript  规范规定:如果一个字符串不符合标准格式,则函数可以使用任何由引擎决定的策略或解析算法。 <code>Date.parse()</code>  对于因包含有无效元素而无法识别的 ISO 格式字符串或者日期应该返回 <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字Not-A-Number。"><code>NaN</code></a></p>
<p>但是, 在如 ECMA-262 规范中定义的情况,如果因为无效值而导致日期字符串不能被识别为 ISO 格式时,根据浏览器和给定的值不同,返回值可以是,也可以不是 <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字Not-A-Number。"><code>NaN</code></a> 。比如:</p>
<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="comment token">// 包含无效值的非 ISO 格式字符串</span>
<span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'23/25/2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
<pre><code class="language-javascript"><code class="language-js"><span class="comment token">// 包含无效值的非 ISO 格式字符串</span>
<span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'23/25/2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></code></pre>
<p>在 Firefox 30 中会被识别为本地时区的2015年12月25日而在 Safari 7 中则是无效日期。但是如果字符串被识别为 ISO 格式并且包含无效值,则在所有遵循 ES5 或者更新标准的浏览器中都会返回 <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字Not-A-Number。"><code>NaN</code></a></p>
<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="comment token">// 包含无效值的 ISO 格式字符串</span>
<pre><code class="language-javascript"><code class="language-js"><span class="comment token">// 包含无效值的 ISO 格式字符串</span>
<span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'2014-25-23'</span><span class="punctuation token">)</span><span class="punctuation token">.</span><span class="function token">toISOString</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"</span></code></pre>
<span class="comment token">// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"</span></code></code></pre>
<p>SpiderMonkey 的引擎策略可以在 <a class="external" href="http://mxr.mozilla.org/mozilla-central/source/js/src/jsdate.cpp?rev=64553c483cd1#889" rel="noopener"><code>jsdate.cpp</code></a>  中找到。字符串 <code>"10 06 2014"</code>  可以作为非 ISO 格式字符串使用自定义处理方式的例子。参见这篇关于解析如何进行的<a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1023155#c6" rel="noopener">粗略纲要</a></p>
<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'10 06 2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
<pre><code class="language-javascript"><code class="language-js"><span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'10 06 2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></code></pre>
<p>将会被解析为本地时间 2014年10月6日而不是6月10日。另一个例子</p>
<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'foo-bar 2014'</span><span class="punctuation token">)</span><span class="punctuation token">.</span><span class="function token">toString</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<pre><code class="language-javascript"><code class="language-js"><span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'foo-bar 2014'</span><span class="punctuation token">)</span><span class="punctuation token">.</span><span class="function token">toString</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// 返回: "Invalid Date"</span>
Date<span class="punctuation token">.</span><span class="function token">parse</span><span class="punctuation token">(</span><span class="string token">'foo-bar 2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// 返回: NaN</span></code></pre>
<span class="comment token">// 返回: NaN</span></code></code></pre>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_parse" name="Example:_Using_parse">例子:使用 <code>Date.parse()</code></h3>
<p>如果 <code>IPOdate</code> 是一个已经存在的 <a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 对象,则可以把其设置为本地时间 1995年8月9日。如下</p>
<pre class="brush: js line-numbers language-js"><code class="language-js">IPOdate<span class="punctuation token">.</span><span class="function token">setTime</span><span class="punctuation token">(</span>Date<span class="punctuation token">.</span><span class="function token">parse</span><span class="punctuation token">(</span><span class="string token">'Aug 9, 1995'</span><span class="punctuation token">)</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
<pre><code class="language-javascript"><code class="language-js">IPOdate<span class="punctuation token">.</span><span class="function token">setTime</span><span class="punctuation token">(</span>Date<span class="punctuation token">.</span><span class="function token">parse</span><span class="punctuation token">(</span><span class="string token">'Aug 9, 1995'</span><span class="punctuation token">)</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></code></pre>
<p>其他一些解析非标准格式日期的例子:</p>
<pre class="brush: js">Date.parse("Aug 9, 1995");
</pre>
<pre><code class="language-javascript">Date.parse("Aug 9, 1995");
</code></pre>
<p>在时区 GMT-0300 中返回 807937200000 ,在其他时区中返回另外的值,因为未指定时区并且不是 ISO 格式,所以默认使用本地时区。</p>
<pre class="brush: js">Date.parse("Wed, 09 Aug 1995 00:00:00 GMT");
</pre>
<pre><code class="language-javascript">Date.parse("Wed, 09 Aug 1995 00:00:00 GMT");
</code></pre>
<p>因为指定了时区 GMT (UTC),所以不管本地时区如何,总是返回 <code>807926400000</code></p>
<pre class="brush: js">Date.parse("Wed, 09 Aug 1995 00:00:00");
</pre>
<pre><code class="language-javascript">Date.parse("Wed, 09 Aug 1995 00:00:00");
</code></pre>
<p>在时区 GMT-0300 中返回 807937200000 ,在其他时区中返回另外的值,因为没有时区标志并且不是 ISO 格式,所以作为本地时区处理。</p>
<pre class="brush: js">Date.parse("Thu, 01 Jan 1970 00:00:00 GMT");
</pre>
<pre><code class="language-javascript">Date.parse("Thu, 01 Jan 1970 00:00:00 GMT");
</code></pre>
<p>因为指定了时区 GMT (UTC),所以不管本地时区如何,总是返回<code> 0</code></p>
<pre class="brush: js">Date.parse("Thu, 01 Jan 1970 00:00:00");
</pre>
<pre><code class="language-javascript">Date.parse("Thu, 01 Jan 1970 00:00:00");
</code></pre>
<p>在时区 GMT-0400 中返回 <code>14400000</code>,在其他时区中返回另外的值,因为未指定时区并且不是 ISO 格式,所以使用本地时区处理。</p>
<pre class="brush: js">Date.parse("Thu, 01 Jan 1970 00:00:00 GMT-0400");
</pre>
<pre><code class="language-javascript">Date.parse("Thu, 01 Jan 1970 00:00:00 GMT-0400");
</code></pre>
<p>因为指定了时区 GMT (UTC),所以不管本地时区如何,总是返回<code> </code><code>14400000</code></p>
<h2 id="规范">规范</h2>
<table class="standard-table">

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-setdate.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"><code><var>dateObj</var>.setDate(<em>dayValue</em>)</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setDate(<em>dayValue</em>)</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>dayValue</code></dt>
@@ -14,9 +14,9 @@
<p>如果 <code>dayValue</code> 超出了月份的合理范围,<code>setDate</code> 将会相应地更新 <code>Date</code> 对象。例如,如果为 <code>dayValue</code> 指定0那么日期就会被设置为上个月的最后一天。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_setDate" name="Example:_Using_setDate">例子:使用<code>setDate</code>方法</h3>
<pre class="brush:js">var theBigDay = new Date(1962, 6, 7); // 1962-07-07
<pre><code class="language-js">var theBigDay = new Date(1962, 6, 7); // 1962-07-07
theBigDay.setDate(24); // 1962-07-24
theBigDay.setDate(32);  // 1962-08-01</pre>
theBigDay.setDate(32);  // 1962-08-01</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setfullyear.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 language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.setFullYear(yearValue[, monthValue[, dayValue]])</code></pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.setFullYear(yearValue[, monthValue[, dayValue]])</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>yearValue</code></dt>
@@ -19,8 +19,8 @@
<p>如果有一个参数超出了合理的范围,<code>setFullYear</code> 方法会更新其他参数值,日期对象的日期值也会被相应更新。 例如,为 <code>monthValue </code>指定 15 则年份会加1月份值会为3。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_setFullYear" name="Example:_Using_setFullYear">例子:使用<code>setFullYear</code>方法</h3>
<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> theBigDay <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
theBigDay<span class="punctuation token" style="color: #999999;">.</span><span class="function token">setFullYear<span class="punctuation token" style="color: #999999;">(</span></span><span class="number token" style="color: #990055;">1997</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre>
<pre><code class="language-js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> theBigDay <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span>
theBigDay<span class="punctuation token" style="color: #999999;">.</span><span class="function token">setFullYear<span class="punctuation token" style="color: #999999;">(</span></span><span class="number token" style="color: #990055;">1997</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,10 +4,10 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-sethours.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">dateObj.setHours(<em>hoursValue</em>[, <em>minutesValue</em>[, <em>secondsValue</em><span style="line-height: normal;">[</span><span style="line-height: normal;">, </span><em>msValue</em><span style="line-height: normal;">]]])</span>
</pre>
<pre><code class="language-javascript">dateObj.setHours(<em>hoursValue</em>[, <em>minutesValue</em>[, <em>secondsValue</em><span style="line-height: normal;">[</span><span style="line-height: normal;">, </span><em>msValue</em><span style="line-height: normal;">]]])</span>
</code></pre>
<h3 id="Versions_prior_to_JavaScript_1.3" name="Versions_prior_to_JavaScript_1.3">JavaScript 1.3版本之前</h3>
<pre class="syntaxbox"><code>dateObj.setHours(<em>hoursValue</em>) </code></pre>
<pre><code class="language-javascript"><code>dateObj.setHours(<em>hoursValue</em>) </code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>hoursValue</code></dt>
@@ -24,9 +24,9 @@
<p>如果有一个参数超出了合理范围,<code>setHours</code> 会相应地更新日期对象中的日期信息。例如,如果为 <code>secondsValue</code> 指定了 100则分钟会加 1然后秒数使用 40。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_setHours" name="Example:_Using_setHours">例子:使用<code>setHours方法</code></h3>
<pre class="brush:js">var theBigDay = new Date();
<pre><code class="language-js">var theBigDay = new Date();
theBigDay.setHours(7);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setmilliseconds.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</var>.setMilliseconds(<em>millisecondsValue</em>)</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setMilliseconds(<em>millisecondsValue</em>)</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>millisecondsValue</code></dt>
@@ -14,9 +14,9 @@
<p>如果指定的数字超出了合理范围,则日期对象的时间信息会被相应地更新。例如,如果指定了 1005则秒数加 1豪秒数为 5。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_setMilliseconds" name="Example:_Using_setMilliseconds">例子:使用<code>setMilliseconds</code></h3>
<pre class="brush:js">var theBigDay = new Date();
<pre><code class="language-js">var theBigDay = new Date();
theBigDay.setMilliseconds(100);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,9 +4,9 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-setminutes.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</var>.setMinutes(<em>minutesValue</em>[, <em>secondsValue</em>[, <em>msValue</em>]])</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setMinutes(<em>minutesValue</em>[, <em>secondsValue</em>[, <em>msValue</em>]])</code></pre>
<h3 id="Versions_prior_to_JavaScript_1.3" name="Versions_prior_to_JavaScript_1.3"> JavaScript 1.3之前版本</h3>
<pre class="syntaxbox"><var>dateObj</var>.setMinutes(<em>minutesValue</em>)</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setMinutes(<em>minutesValue</em>)</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>minutesValue</code></dt>
@@ -25,9 +25,9 @@
<p>如果有一个指定的参数超出了合理范围,<code>setMinutes</code> 会相应地更新日期对象中的时间信息。例如,为 <code>secondsValue</code> 指定 100分钟数将会加 1而秒数会为 40。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_setMinutes" name="Example:_Using_setMinutes">例子:使用<code>setMinutes方法</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setMinutes(45);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,9 +3,9 @@
<p><code><strong>setMonth()</strong></code> 方法根据本地时间为一个设置年份的日期对象设置月份。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-setmonth.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><var>dateObj</var>.setMonth(<em>monthValue</em>[, <em>dayValue</em>])</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setMonth(<em>monthValue</em>[, <em>dayValue</em>])</code></pre>
<h3 id="Versions_prior_to_JavaScript_1.3" name="Versions_prior_to_JavaScript_1.3">JavaScript 1.3版本之前</h3>
<pre class="syntaxbox"><var>dateObj</var>.setMonth(<em>monthValue</em>)</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setMonth(<em>monthValue</em>)</code></pre>
<h3 id="Parameter" name="Parameter">参数</h3>
<dl>
<dt><code>monthValue</code></dt>
@@ -22,9 +22,9 @@
<p>如果有一个指定的参数超出了合理范围,<code>setMonth</code> 会相应地更新日期对象中的日期信息。<font face="Courier New, Andale Mono, monospace">例如,为</font> <code>monthValue</code> 指定 15则年份会加 1月份将会使用 3。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_setMonth" name="Example:_Using_setMonth">例子:使用<code>setMonth方法</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setMonth(6);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,9 +4,9 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-setseconds.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</var>.setSeconds(<em>secondsValue</em>[, <em>msValue</em>])</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setSeconds(<em>secondsValue</em>[, <em>msValue</em>])</code></pre>
<h3 id="JavaScript_1.3之前版本">JavaScript 1.3之前版本</h3>
<pre class="syntaxbox"><var>dateObj</var>.setSeconds(<em>secondsValue</em>)</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setSeconds(<em>secondsValue</em>)</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>secondsValue</code></dt>
@@ -19,9 +19,9 @@
<p>如果一个参数超出了合理范围, <code>setSeconds</code> 方法会相应地更新日期对象的时间信息。例如,为 <code>secondsValue</code> 指定 100则日期对象的分钟数会相应地加 1秒数将会使用 40。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_setSeconds" name="Example:_Using_setSeconds">例子:使用<code>setSeconds方法</code></h3>
<pre class="brush:js">var theBigDay = new Date();
<pre><code class="language-js">var theBigDay = new Date();
theBigDay.setSeconds(30)
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-settime.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</var>.setTime(<em>timeValue</em>)</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setTime(<em>timeValue</em>)</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>timeValue</code></dt>
@@ -17,7 +17,7 @@
<pre>theBigDay = new Date("July 1, 1999");
sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setutcdate.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"><code><var>dateObj</var>.setUTCDate(<var>dayValue</var>)</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setUTCDate(<var>dayValue</var>)</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>dayValue</code></dt>
@@ -14,9 +14,9 @@
<p>如果你指定的参数超出了范围setUTCDate()会尝试更新对应的<a href="Reference/Global_Objects/Date" title="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 https://github.com/mdn/interactive-examples and send us a pull request."><code>Date</code></a> 中的日期信息。例如如果你使用了40来作为参数但是<a href="Reference/Global_Objects/Date" title="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 https://github.com/mdn/interactive-examples and send us a pull request."><code>Date</code></a> 中存储的月份为6月那么日期将被改写为10且月份被增到7月。</p>
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Using_setUTCDate" name="Example:_Using_setUTCDate">使用Using <code>setUTCDate()</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setUTCDate(20);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setutcfullyear.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="语法">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.setUTCFullYear(<var>yearValue</var>[, <var>monthValue</var>[, <var>dayValue</var>]])</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setUTCFullYear(<var>yearValue</var>[, <var>monthValue</var>[, <var>dayValue</var>]])</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>yearValue</code></dt>
@@ -19,9 +19,9 @@
<p>如果你指定的参数超出了期待范围,<code>setUTCFullYear()方法将会根据Date对象更新其他参数和日期信息。例如如果你将monthValue设定为15年份会增加1月份值则为为3。</code></p>
<h2 id="例子">例子</h2>
<h3 id="使用_setUTCFullYear()">使用 <code>setUTCFullYear()</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setUTCFullYear(1997);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setutchours.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">Syntax</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.setUTCHours(<var>hoursValue</var>[, <var>minutesValue</var>[, <var>secondsValue</var>[, <var>msValue</var>]]])</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setUTCHours(<var>hoursValue</var>[, <var>minutesValue</var>[, <var>secondsValue</var>[, <var>msValue</var>]]])</code></code></pre>
<h3 id="参数"> 参数</h3>
<dl>
<dt><code>hoursValue</code></dt>
@@ -23,9 +23,9 @@
<p>If a parameter you specify is outside of the expected range, <code>setUTCHours()</code> attempts to update the date information in the <a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> object accordingly. For example, if you use 100 for <code>secondsValue</code>, the minutes will be incremented by 1 (<code>minutesValue + 1</code>), and 40 will be used for seconds.</p>
<h2 id="例子">例子</h2>
<h3 id="使用_setUTCHours()">使用 <code>setUTCHours()</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setUTCHours(8);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setutcmilliseconds.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="语法">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.setUTCMilliseconds(<var>millisecondsValue</var>)</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setUTCMilliseconds(<var>millisecondsValue</var>)</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>millisecondsValue</code></dt>
@@ -16,9 +16,9 @@
<p>如果传递的参数超出了指定的范围,<code>setUTCMilliseconds() 方法会相应地尝试更新储存在 </code><a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a>  的时间信息。例如,假设你传递参数的值是 1100存储在 <a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 的秒数会加 1然后使用 100 来作为毫秒数。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_setUTCMilliseconds()_方法">使用 <code>setUTCMilliseconds() 方法</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setUTCMilliseconds(500);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -5,7 +5,7 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-setutcminutes.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="语法">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.setUTCMinutes(<var>minutesValue</var>[, <var>secondsValue</var>[, <var>msValue</var>]])</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setUTCMinutes(<var>minutesValue</var>[, <var>secondsValue</var>[, <var>msValue</var>]])</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>minutesValue</code></dt>
@@ -22,9 +22,9 @@
<p>如果你传入的参数值在上文所述范围之外的话,<code><strong>setUTCMinutes()</strong></code>方法会尝试修改日期对象中的其他信息,比如说你为<code><strong>secondsValue</strong></code>这个参数传入了100译者注规定范围是[0, 59]),那么第一个参数(<code><strong>minutesValue</strong></code>就会被加1而秒数则变成了40。</p>
<h2 id="例子">例子</h2>
<h3 id="使用_setUTCMinutes()">使用 <code>setUTCMinutes()</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setUTCMinutes(43);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setutcmonth.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="语法">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.setUTCMonth(<var>monthValue</var>[, <var>dayValue</var>])</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setUTCMonth(<var>monthValue</var>[, <var>dayValue</var>])</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>monthValue</code></dt>
@@ -19,9 +19,9 @@
<p>如果你写了一个超过在规定的范围内的参数. <code>setUTCMonth()就会试图相应的更新时间信息在Data对象中。例如如果你用15作为</code>monthValue的值那么年份就会加1并且月份会变成3.15=12+3</p>
<h2 id="示例">示例</h2>
<h3 id="使用_setUTCMonth()">使用 <code>setUTCMonth()</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setUTCMonth(11);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-setutcseconds.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="语法">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.setUTCSeconds(<var>secondsValue</var>[, <var>msValue</var>])</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.setUTCSeconds(<var>secondsValue</var>[, <var>msValue</var>])</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>secondsValue</code></dt>
@@ -19,9 +19,9 @@
<p>如果你指定的值超出了范围, <code>setUTCSeconds()</code> 因此会更新<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 对象中date的相关信息 . 举个例子, 如果你设置secondsValue为100, <a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 对象中的分钟数会增加1 并且秒数会变成40.</p>
<h2 id="示例">示例</h2>
<h3 id="使用_setUTCSeconds()">使用 <code>setUTCSeconds()</code></h3>
<pre class="brush: js">var theBigDay = new Date();
<pre><code class="language-javascript">var theBigDay = new Date();
theBigDay.setUTCSeconds(20);
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,7 +4,7 @@
</div></div>
<p>The <code><strong>setYear()</strong></code> method sets the year for a specified date according to local time. Because <code>setYear</code> does not set full years ("year 2000 problem"), it is no longer used and has been replaced by the <a href="Reference/Global_Objects/Date/setFullYear" title="setFullYear() 方法根据本地时间为一个日期对象设置年份。"><code>setFullYear</code></a> method.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox"><var>dateObj</var>.setYear(<em>yearValue</em>)</pre>
<pre><code class="language-javascript"><var>dateObj</var>.setYear(<em>yearValue</em>)</code></pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<dl>
<dt><code>yearValue</code></dt>
@@ -20,7 +20,7 @@
theBigDay.setYear(96);
theBigDay.setYear(1996);
theBigDay.setYear(2000);
</pre>
</code></pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,16 +4,16 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-todatestring.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"><code><var>dateObj</var>.toDateString()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.toDateString()</code></code></pre>
<h2 id="Description" name="Description">描述</h2>
<p><a href="Reference/Global_Objects/Date" title="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 https://github.com/mdn/interactive-examples and send us a pull request."><code>Date</code></a> 对象实例引用一个具体的时间点。调用 <a href="Reference/Global_Objects/Date/toString" title="toString() 方法返回一个字符串表示该Date对象。"><code>toString</code></a> 方法会以美式英语和人类易读的形式返回日期对象的格式化字符串。在 <a href="/en-US/docs/SpiderMonkey" title="SpiderMonkey">SpiderMonkey</a> 里,该字符串由日期部分(年月日)和其后的时间部分(时分秒及时区)组成。有时需要获取日期部分的字符串,这可以由 <code>toDateString</code> 方法完成。</p>
<p>The <code>toDateString</code> method is especially useful because compliant engines implementing <a href="/en-US/docs/ECMAScript" title="ECMAScript">ECMA-262</a> may differ in the string obtained from <code>toString</code> for <code>Date</code> objects, as the format is implementation-dependent and simple string slicing approaches may not produce consistent results across multiple engines.</p>
<h2 id="Example" name="Example">例子</h2>
<h3 id="Example:_A_basic_usage_of_toDateString" name="Example:_A_basic_usage_of_toDateString">例子:<code>toDateString</code> 方法的简单使用</h3>
<pre class="brush:js">var d = new Date(1993, 6, 28, 14, 39, 7);
<pre><code class="language-js">var d = new Date(1993, 6, 28, 14, 39, 7);
println(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
println(d.toDateString()); // prints Wed Jul 28 1993</pre>
println(d.toDateString()); // prints Wed Jul 28 1993</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -5,15 +5,15 @@
<p>The <code><strong>toGMTString()</strong></code> method converts a date to a string, using Internet GMT conventions. The exact format of the value returned by <code>toGMTString</code> varies according to the platform and browser, in general it should represent a human readable date string.</p>
<p><strong>Note</strong>: <code>toGMTString</code> is deprecated and should no longer be used, it's only there for backwards compatibility, use <a href="Reference/Global_Objects/Date/toUTCString" title="toUTCString() 方法把一个日期转换为一个字符串使用UTC时区。"><code>toUTCString()</code></a> instead.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox"><var>dateObj</var>.toGMTString()</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toGMTString()</code></pre>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example:_Using_toGMTString" name="Example:_Using_toGMTString">Example: Using <code>toGMTString</code></h3>
<p>In this example, the <code>toGMTString</code> method converts the date to GMT (UTC) using the operating system's time-zone offset and returns a string value that is similar to the following form. The exact format depends on the platform.</p>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var str = today.toGMTString(); // deprecated! use toUTCString()
console.log(str); // Mon, 18 Dec 1995 17:28:35 GMT
</pre>
</code></pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,15 +4,15 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-toisostring.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</var>.toISOString()</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toISOString()</code></pre>
<h2 id="例子">例子</h2>
<pre class="brush: js">var today = new Date("05 October 2011 14:48 UTC");
<pre><code class="language-javascript">var today = new Date("05 October 2011 14:48 UTC");
alert(today.toISOString()); // 返回2011-10-05T14:48:00.000Z
</pre>
</code></pre>
<p>上例使用了非标准字符串的解析该字符串在某些旧的浏览器如IE中可能无法被正确解析。</p>
<h2 id="Description" name="Description">Polyfill</h2>
<p>该方法在ECMA-262第5版中被标准化。对于那些不支持此方法的JS引擎可以通过加上下面的代码实现</p>
<pre class="brush:js">if ( !Date.prototype.toISOString ) {
<pre><code class="language-js">if ( !Date.prototype.toISOString ) {
( function() {
function pad(number) {
@@ -34,7 +34,7 @@ alert(today.toISOString()); // 返回2011-10-05T14:48:00.000Z
};
}() );
}</pre>
}</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,13 +4,13 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-tojson.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"><code><var>dateObj</var>.toJSON()</code>
</pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.toJSON()</code>
</code></pre>
<h2 id="Description" name="Description">描述</h2>
<p><a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 实例引用一个具体的时间点。 调用 <code>toJSON()</code> 返回一个 JSON 格式字符串(使用 <a href="Reference/Global_Objects/Date/toISOString" title="toISOString() 方法返回一个 ISOISO 8601 Extended Format格式的字符串 YYYY-MM-DDTHH:mm:ss.sssZ。时区总是UTC协调世界时加一个后缀“Z”标识。"><code>toISOString()</code></a>),表示该日期对象的值。默认情况下,这个方法常用于 <a class="glossaryLink" href="/en-US/docs/Glossary/JSON" title="JSON: JavaScript Object Notation (JSON) is a data-interchange format.  Although not a strict subset, JSON closely resembles a subset of JavaScript syntax. Though many programming languages support JSON, JSON is especially useful for JavaScript-based apps, including websites and browser extensions.">JSON</a>序列化<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a>对象。</p>
<h2 id="Example" name="Example">样例</h2>
<h3 id="Example:_Using_toJSON" name="Example:_Using_toJSON"><code>toJSON()</code> 样例</h3>
<pre class="brush:js">var date = new Date();
<pre><code class="language-js">var date = new Date();
console.log(date); //Thu Nov 09 2017 18:54:04 GMT+0800 (中国标准时间)
var jsonDate = (date).toJSON();
@@ -18,7 +18,7 @@ console.log(jsonDate); //"2017-11-09T10:51:11.395Z"
var backToDate = new Date(jsonDate);
console.log(backToDate); //Thu Nov 09 2017 18:54:04 GMT+0800 (中国标准时间)
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-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 class="syntaxbox"><var>dateObj</var>.toLocaleDateString([locales [, options]])</pre>
<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>
@@ -107,15 +107,15 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_toLocaleDateString" name="Example:_Using_toLocaleDateString">例子:使用<code>toLocaleDateString</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));
// 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</pre>
// → "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 class="brush: js">function toLocaleDateStringSupportsLocales() {
<pre><code class="language-javascript">function toLocaleDateStringSupportsLocales() {
try {
new Date().toLocaleDateString("i");
} catch (e) {
@@ -123,10 +123,10 @@ date.toLocaleDateString();
}
return false;
}
</pre>
</code></pre>
<h3 id="Example:_Using_locales" name="Example:_Using_locales">例子:使用<code>locales</code></h3>
<p>下例展示了本地化日期格式的一些变化。为了在应用的用户界面得到某种语言的日期格式,必须确保使用 <code>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));
// formats below assume the local time zone of the locale;
// America/Los_Angeles for the US
@@ -156,10 +156,10 @@ alert(date.toLocaleDateString("ja-JP-u-ca-japanese"));
// Balinese, include a fallback language, in this case Indonesian
alert(date.toLocaleDateString(["ban", "id"]));
// → "20/12/2012"
</pre>
</code></pre>
<h3 id="Example:_Using_options" name="Example:_Using_options">例子:使用<code>options</code></h3>
<p>可以使用 <code>options </code>参数来自定义 <code>toLocaleDateString</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));
// request a weekday along with a long date
var options = {weekday: "long", year: "numeric", month: "long", day: "numeric"};
@@ -171,7 +171,7 @@ options.timeZone = "UTC";
options.timeZoneName = "short";
alert(date.toLocaleDateString("en-US", options));
// → "Thursday, December 20, 2012, GMT"
</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>

View File

@@ -5,7 +5,7 @@
</div></div>
<p>非标准方法 <strong><code>toLocaleFormat()</code></strong> 按特定的格式将一个日期转换成一个字符串。 <a href="Reference/Global_Objects/DateTimeFormat" title="交互示例的源代码存储在 GitHub 资源库。如果你愿意分布交互示例请复制https://github.com/mdn/interactive-examples并向我们发送一个pull请求。"><code>Intl.DateTimeFormat</code></a> 是符合标准的格式化日期的替代方法。另见更新的(newer)版本的 <a href="Reference/Global_Objects/Date/toLocaleDateString" title="toLocaleDateString() 方法返回该日期对象日期部分的字符串该字符串格式因不同语言而不同。新增的参数 locales  options 使程序能够指定使用哪种语言格式化规则允许定制该方法的表现behavior。在旧版本浏览器中 locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。"><code>Date.prototype.toLocaleDateString()</code></a>方法.</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.toLocaleFormat(<var>formatString</var>)</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.toLocaleFormat(<var>formatString</var>)</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>formatString</code></dt>
@@ -17,19 +17,19 @@
<p>Also note that the behavior of the used locale depends on the platform, and the user might customize the locale used, so using the system locale the choose the format string might in some cases not even be adequate. You might consider using some of the more general <code>toLocale*</code> methods of the <a href="Reference/Global_Objects/Date" title="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 https://github.com/mdn/interactive-examples and send us a pull request."><code>Date</code></a> object or doing your own custom localization of the date to be displayed using some of the <code>get*</code> methods of the <a href="Reference/Global_Objects/Date" title="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 https://github.com/mdn/interactive-examples and send us a pull request."><code>Date</code></a> object instead of using this method.</p>
<h2 id="示例">示例</h2>
<h3 id="Using_toLocaleFormat()">Using <code>toLocaleFormat()</code></h3>
<pre class="brush: js">var today = new Date();
<pre><code class="language-javascript">var today = new Date();
var date = today.toLocaleFormat('%A, %B %e, %Y'); // Bad example
</pre>
</code></pre>
<p>In this example, <code>toLocaleFormat()</code> returns a string such as "Wednesday, October 3, 2007". Note that the format string in this example is not properly localized, which will result in the problems described above.</p>
<h2 id="腻子(Polyfill)">腻子(Polyfill)</h2>
<p>When using the <a class="external" href="https://github.com/abritinthebay/datejs/wiki/Format-Specifiers" rel="noopener">DateJS</a> library you can polyfill <a href="Reference/Global_Objects/Date/toLocaleDateString" title="toLocaleDateString() 方法返回该日期对象日期部分的字符串该字符串格式因不同语言而不同。新增的参数 locales  options 使程序能够指定使用哪种语言格式化规则允许定制该方法的表现behavior。在旧版本浏览器中 locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。"><code>Date.prototype.toLocaleDateString()</code></a> like this:</p>
<pre class="brush: js">if (!Date.prototype.toLocaleFormat) {
<pre><code class="language-javascript">if (!Date.prototype.toLocaleFormat) {
(function() {
Date.prototype.toLocaleFormat = function(formatString) {
return this.format(formatString);
};
}());
}</pre>
}</code></pre>
<h2 id="标准">标准</h2>
<p>不属于任何标准。在JavaScript 1.6中被实现。</p>
<h2 id="兼容性">兼容性</h2>

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>

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-tolocaletimestring.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</var>.toLocaleTimeString([locales [, options]])</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toLocaleTimeString([locales [, options]])</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>
@@ -12,15 +12,15 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_toLocaleTimeString" name="Example:_Using_toLocaleTimeString">例子:使用 <code>toLocaleTimeString</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));
// toLocaleTimeString without arguments depends on the implementation,
// the default locale, and the default time zone
alert(date.toLocaleTimeString());
// → "7:00:00 PM" if run in en-US locale with time zone America/Los_Angeles</pre>
// → "7:00:00 PM" 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 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 toLocaleTimeStringSupportsLocales() {
<pre><code class="language-javascript">function toLocaleTimeStringSupportsLocales() {
try {
new Date().toLocaleTimeString("i");
} catch (e) {
@@ -28,10 +28,10 @@ alert(date.toLocaleTimeString());
}
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));
// formats below assume the local time zone of the locale;
// America/Los_Angeles for the US
@@ -56,10 +56,10 @@ alert(date.toLocaleTimeString("ar-EG"));
// Balinese, include a fallback language, in this case Indonesian
alert(date.toLocaleTimeString(["ban", "id"]));
// → "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;">toLocaleTimeString</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));
// an application may want to use UTC and make that visible
var options = {timeZone: "UTC", timeZoneName: "short"};
@@ -69,7 +69,7 @@ alert(date.toLocaleTimeString("en-US", options));
// sometimes even the US needs 24-hour time
alert(date.toLocaleTimeString("en-US", {hour12: false}));
// → "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>

View File

@@ -5,8 +5,8 @@
</div></div>
<p><strong><code>toSource() </code></strong>返回表示源代码的字符串。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>dateObj</var>.toSource()
Date.toSource()</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toSource()
Date.toSource()</code></pre>
<h3 id="返回值">返回值</h3>
<p> 表示<a href="Reference/Global_Objects/Date" title="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 https://github.com/mdn/interactive-examples and send us a pull request."><code>Date</code></a> 源代码的字符串</p>
<h2 id="描述">描述</h2>
@@ -14,10 +14,10 @@ Date.toSource()</pre>
<ul>
<li>对于内置的<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 对象, <code>toSource()</code> 返回以下字符串,表示源代码不可用:
<pre class="brush: js">function Date() {
<pre><code class="language-javascript">function Date() {
[native code]
}
</pre>
</code></pre>
</li>
<li>对于<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a>的实例, <code>toSource()</code> 返回表示该日期源代码的字符串.</li>
</ul>

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-tostring.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</var>.toString()</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toString()</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h2 id="Description" name="Description">描述</h2>
@@ -15,10 +15,10 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_toString" name="Example:_Using_toString">例子: 使用 <code>toString</code> 方法</h3>
<p>下例把一个<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a>对象的 <code>toString</code> 返回值赋给 <code>myVar</code></p>
<pre class="brush:js">var x = new Date();
<pre><code class="language-js">var x = new Date();
myVar = x.toString(); // 把类似于下面格式的值赋给 myVar
// Mon Sep 28 1998 14:36:22 GMT-0700 (Pacific Daylight Time)
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,17 +4,17 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-totimestring.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</var>.toTimeString()</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toTimeString()</code></pre>
<h2 id="Description" name="Description">描述</h2>
<p><a href="Reference/Global_Objects/Date" title="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 https://github.com/mdn/interactive-examples and send us a pull request."><code>Date</code></a> 对象的实例引用一个具体的时间点。 调用 <a href="Reference/Global_Objects/Date/toString" title="toString() 方法返回一个字符串表示该Date对象。"><code>toString</code></a> 方法以美式英语和人类易读的形式,返回日期对象的格式化字符串。在 <a href="/en-US/docs/SpiderMonkey" title="SpiderMonkey">SpiderMonkey</a> 里,该字符串由日期部分(年月日)和其后的时间部分(时分秒和时区)组成。有时会需要获取时间部分的字符串,这可以由 <code>toTimeString</code> 方法完成。</p>
<p>The <code style="font-style: normal;">toTimeString</code> method is especially useful because compliant engines implementing <a href="https://developer.mozilla.org/en-US/docs/ECMAScript" title="ECMAScript">ECMA-262</a> may differ in the string obtained from <code style="font-style: normal;">toString</code> for <code style="font-style: normal;">Date</code> objects, as the format is implementation-dependent; simple string slicing approaches may not produce consistent results across multiple engines.</p>
<h2 id="Example" name="Example">例子</h2>
<h3 id="Example:_A_basic_usage_of_toTimeString" name="Example:_A_basic_usage_of_toTimeString">例子:<code>toTimeString</code> 方法的简单使用</h3>
<pre class="brush:js">var d = new Date(1993, 6, 28, 14, 39, 7);
<pre><code class="language-js">var d = new Date(1993, 6, 28, 14, 39, 7);
println(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
println(d.toTimeString()); // prints 14:39:07 GMT-0600 (PDT)
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

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-toutcstring.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</var>.toUTCString()</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toUTCString()</code></pre>
<h3 id="Parameters" name="Parameters">返回值</h3>
<p>返回使用UTC时区表示给定日期的字符串</p>
<p> </p>
@@ -15,7 +15,7 @@
<pre>var today = new Date();
var UTCstring = today.toUTCString();
// Mon, 03 Jul 2006 21:44:38 GMT
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -3,7 +3,7 @@
<p><code><strong>valueOf()</strong></code> 方法返回一个 <a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 对象的原始值。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-valueof.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>dateObj</var>.valueOf()</code></pre>
<pre><code class="language-javascript"><code><var>dateObj</var>.valueOf()</code></code></pre>
<h3 id="Parameters" name="Parameters">返回值</h3>
<p>从1970年1月1日0时0分0秒UTC即协调世界时到该日期的毫秒数。</p>
<h2 id="Description" name="Description">描述</h2>
@@ -12,9 +12,9 @@
<p>该方法通常在 JavaScript 内部被调用,而不是在代码中显式调用。</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_valueOf" name="Example:_Using_valueOf">使用 <code>valueOf()</code></h3>
<pre class="brush:js">var x = new Date(56, 6, 17);
<pre><code class="language-js">var x = new Date(56, 6, 17);
var myVar = x.valueOf(); // assigns -424713600000 to myVar
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>