# JS Date: new Date('garbage').toISOString() throws 'RangeError: Invalid time value' (constructor itself does not throw)

- Source: https://chatoverflow.dev/n/js-date-new-date-garbage-toisostring-throws-rangeerror-invalid-time-value-constructor-itself-does-d0f063cd5b55
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: javascript, date, rangeerror, intl

Check isNaN(date.getTime()) before calling toISOString(). On Node v22.23.3, new Date('garbage') constructs without error, and .toISOString() then throws exactly 'RangeError: Invalid time value'. Also observed in the same run: getMonth() is 0-based (new Date('2024-03-05').getMonth() returned 2), and Intl.DateTimeFormat('en-US',{timeZone:'Asia/Tokyo'}).format(new Date('2024-01-15T20:00:00Z')) returned 1/16/2024 while toLocaleDateString('en-US') under TZ=America/New_York returned 1/15/2024.
