2019-04-21 11:50:48 +08:00

30 lines
3.4 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div></div>
<h2 id="消息">消息</h2>
<pre><code class="language-javascript">范围错误: 非法数据(Firefox)
范围错误: 非法时间值 (Chrome)
范围错误: 提供的数据不是有效的 (Chrome)
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p><a href="Reference/Global_Objects/RangeError" title="RangeError对象标明一个错误当一个值不在其所允许的范围或者集合中。"><code>RangeError</code></a></p>
<h2 id="哪里出错了">哪里出错了?</h2>
<p><a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a> 或 <a href="Reference/Global_Objects/Date/parse" title="Date.parse() 方法解析一个表示某个日期的字符串并返回从1970-1-1 00:00:00 UTC 到该日期对象该日期对象的UTC时间的毫秒数如果该字符串无法识别或者一些情况下包含了不合法的日期数值2015-02-31则返回值为NaN。"><code>Date.parse()</code></a> 提供了一个会导致无效日期的字符串。</p>
<h2 id="示例">示例</h2>
<h3 id="错误示例">错误示例</h3>
<p>ISO格式化字符串中不可识别的字符串或者包含非法元素值的日期一般会返回 <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字Not-A-Number。"><code>NaN</code></a>。然而根据实现的不同不符合ISO格式的字符串可能也会抛出<code> RangeError: invalid date</code>,比如在火狐浏览器中有以下情形:</p>
<pre><code class="language-js example-bad">new Date('foo-bar 2014');
new Date('2014-25-23').toISOString();
new Date('foo-bar 2014').toString();
</code></pre>
<p>然而下面这种情形会返回 <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字Not-A-Number。"><code>NaN</code></a> </p>
<pre><code class="language-js example-bad">Date.parse('foo-bar 2014'); // NaN</code></pre>
<p>参见 <a href="Reference/Global_Objects/Date/parse" title="Date.parse() 方法解析一个表示某个日期的字符串并返回从1970-1-1 00:00:00 UTC 到该日期对象该日期对象的UTC时间的毫秒数如果该字符串无法识别或者一些情况下包含了不合法的日期数值2015-02-31则返回值为NaN。"><code>Date.parse()</code></a> 文档,了解更多详情。</p>
<h3 id="正确示例">正确示例</h3>
<pre><code class="language-js example-good">new Date('05 October 2011 14:48 UTC');</code></pre>
<h2 id="另见">另见</h2>
<ul>
<li><a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a></li>
<li><a href="Reference/Global_Objects/Date/parse" title="Date.parse() 方法解析一个表示某个日期的字符串并返回从1970-1-1 00:00:00 UTC 到该日期对象该日期对象的UTC时间的毫秒数如果该字符串无法识别或者一些情况下包含了不合法的日期数值2015-02-31则返回值为NaN。"><code>Date.prototype.parse()</code></a></li>
<li><a href="Reference/Global_Objects/Date/toISOString" title="toISOString() 方法返回一个 ISOISO 8601 Extended Format格式的字符串 YYYY-MM-DDTHH:mm:ss.sssZ。时区总是UTC协调世界时加一个后缀“Z”标识。"><code>Date.prototype.toISOString()</code></a></li>
</ul>
</article>