Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. JavaScript error reference
  5. RangeError: invalid date

RangeError: invalid date

The JavaScript exception "invalid date" occurs when an invalid date is attempted to be converted to an ISO date string.

Message

RangeError: Invalid time value (V8-based)RangeError: invalid date (Firefox)RangeError: Invalid Date (Safari)

Error type

RangeError

What went wrong?

You are converting aninvalid date value to an ISO date string. This usually happens in one of three ways:

Aninvalid date is produced when you attempt to parse an invalid date string, or set the timestamp to an out-of-bounds value. Invalid dates usually cause all date methods to returnNaN or other special values. However, such dates do not have valid ISO string representations, so an error is thrown when you attempt to do so.

Examples

Invalid cases

js
const invalid = new Date("nothing");invalid.toISOString(); // RangeError: invalid dateinvalid.toJSON(); // RangeError: invalid dateJSON.stringify({ date: invalid }); // RangeError: invalid date

However, most other methods return special values:

js
invalid.toString(); // "Invalid Date"invalid.getDate(); // NaN

For more details, see theDate.parse() documentation.

Valid cases

js
new Date("05 October 2011 14:48 UTC").toISOString(); // "2011-10-05T14:48:00.000Z"new Date(1317826080).toISOString(); // "2011-10-05T14:48:00.000Z"

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp