I'm getting frequent errors when i start my server. Here is the error:
RangeError: Invalid time value at Date.toISOString ()
Here is the code:
var start = timestamp;
const expiryDate = (new Date(start)).toISOString().split('T')[0];
The "Uncaught RangeError: Invalid time value" error occurs when calling a method on an invalid date, e.g. new Date('asdf'). toISOString() . To solve the error, conditionally check if the date is valid before calling the method on it.
The JavaScript exception "invalid date" occurs when a string leading to an invalid date has been provided to Date or Date.
This exception occurs when the Date object contains an invalid date.
new Date('undefined').toISOString()
In this example the Date object can be created without any problems, but the toISOString function throws an Error.
To fix your issue, you need to make sure that the timestamp variable contains a valid date string.
In my case endDate
had a null
value:
const [date, setDate] = useState([
{
startDate: new Date(),
endDate: null,
key: "selection",
},
]);
Changing it to new Date()
solved the issue:
const [date, setDate] = useState([
{
startDate: new Date(),
endDate: new Date(),
key: "selection",
},
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With