RangeError: invalid date - JavaScript 编辑
The JavaScript exception "invalid date" occurs when a string leading to an invalid date has been provided to Date
or Date.parse()
.
Message
RangeError: invalid date (Edge) RangeError: invalid date (Firefox) RangeError: invalid time value (Chrome) RangeError: Provided date is not in valid range (Chrome)
Error type
What went wrong?
A string leading to an invalid date has been provided to Date
or Date.parse()
.
Examples
Invalid cases
Unrecognizable strings or dates containing illegal element values in ISO formatted strings usually return NaN
. However, depending on the implementation, non–conforming ISO format strings, may also throw RangeError: invalid date
, like the following cases in Firefox:
new Date('foo-bar 2014');
new Date('2014-25-23').toISOString();
new Date('foo-bar 2014').toString();
This, however, returns NaN
in Firefox:
Date.parse('foo-bar 2014'); // NaN
For more details, see the Date.parse()
documentation.
Valid cases
new Date('05 October 2011 14:48 UTC');
new Date(1317826080); // Unix Time Stamp for 05 October 2011 14:48:00 UTC
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论