Here is code
const dateStr = '1989-11-11T03:34'; let date = new Date(dateStr); console.log(date.toUTCString()); console.log(+date);
Fri, 10 Nov 1989 22:34:00 GMT 626740440000 <--- far future
Why unix time is in far future?
Here is Playcode link
It’s not wrong.
You seem to have two issues with what you’re getting:
- The time isn’t the same in your
- The number you’re getting from
+dateisn’t what you expect.
But both are correct:
- The string has no timezone indicator on it, so since it’s a date+time string, it’s parsed as local time. This is covered by the Date Time String Format section of the specification. But your output is showing GMT (because
626740440000is the number of milliseconds since The Epoch, not seconds as it was in the original Unix epoch scheme. This is covered by the Time Values and Time Range section of the specification.
If you want to parse your string as UTC (loosely, GMT), add a
Z to the end of it indicating that’t is in GMT.
If you want the number of seconds since The Epoch, divide
1000 (perhaps rounding or flooring the result).