javascript 范围错误:无效的时间值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54462227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:24:08  来源:igfitidea点击:

RangeError: Invalid time value

javascriptnode.js

提问by adeboye0

I'm getting frequent errors when i start my server. Here is the error:

启动服务器时经常出现错误。这是错误:

RangeError: Invalid time value at Date.toISOString ()

RangeError: Date.toISOString () 处的时间值无效

Here is the code:

这是代码:

var start = timestamp;
const expiryDate = (new Date(start)).toISOString().split('T')[0];

回答by Stee

This exception occurs when the Date object contains an invalid date.

当 Date 对象包含无效日期时会发生此异常。

new Date('undefined').toISOString()

In this example the Date object can be created without any problems, but the toISOString function throws an Error.

在此示例中,可以毫无问题地创建 Date 对象,但 toISOString 函数会引发错误。

To fix your issue, you need to make sure that the timestamp variable contains a valid date string.

要解决您的问题,您需要确保时间戳变量包含有效的日期字符串。