aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/invalid_date
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/invalid_date
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/errors/invalid_date')
-rw-r--r--files/zh-cn/web/javascript/reference/errors/invalid_date/index.html54
1 files changed, 54 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/invalid_date/index.html b/files/zh-cn/web/javascript/reference/errors/invalid_date/index.html
new file mode 100644
index 0000000000..1deee46fcc
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/errors/invalid_date/index.html
@@ -0,0 +1,54 @@
+---
+title: 'RangeError: invalid date'
+slug: Web/JavaScript/Reference/Errors/Invalid_date
+tags:
+ - JavaScript
+ - 范围错误
+ - 错误
+translation_of: Web/JavaScript/Reference/Errors/Invalid_date
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="消息">消息</h2>
+
+<pre class="syntaxbox">范围错误: 非法数据(Firefox)
+范围错误: 非法时间值 (Chrome)
+范围错误: 提供的数据不是有效的 (Chrome)
+</pre>
+
+<h2 id="错误类型">错误类型</h2>
+
+<p>{{jsxref("RangeError")}}</p>
+
+<h2 id="哪里出错了">哪里出错了?</h2>
+
+<p>为 {{jsxref("Date")}} 或 {{jsxref("Date.parse()")}} 提供了一个会导致无效日期的字符串。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="错误示例">错误示例</h3>
+
+<p>ISO格式化字符串中不可识别的字符串或者包含非法元素值的日期一般会返回 {{jsxref("NaN")}}。然而,根据实现的不同,不符合ISO格式的字符串可能也会抛出<code> RangeError: invalid date</code>,比如在火狐浏览器中有以下情形:</p>
+
+<pre class="brush: js example-bad">new Date('foo-bar 2014');
+new Date('2014-25-23').toISOString();
+new Date('foo-bar 2014').toString();
+</pre>
+
+<p>然而下面这种情形会返回 {{jsxref("NaN")}} :</p>
+
+<pre class="brush: js example-bad">Date.parse('foo-bar 2014'); // NaN</pre>
+
+<p>参见 {{jsxref("Date.parse()")}} 文档,了解更多详情。</p>
+
+<h3 id="正确示例">正确示例</h3>
+
+<pre class="brush: js example-good">new Date('05 October 2011 14:48 UTC');</pre>
+
+<h2 id="另见">另见</h2>
+
+<ul>
+ <li>{{jsxref("Date")}}</li>
+ <li>{{jsxref("Date.prototype.parse()")}}</li>
+ <li>{{jsxref("Date.prototype.toISOString()")}}</li>
+</ul>