Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

JavaScript parsing year 1 as 2000

$
0
0

I'm experiencing this issue in both Node.js v16.20.2 and in a browser console:

> new Date(Date.parse('0001-01-01'))0001-01-01T00:00:00.000Z

Ok i expected this. Now consider this:

> new Date(Date.parse('0001-01-01 00:00:00'))2000-12-31T23:00:00.000Z

Euhm, year 2000??

This works just fine:

> new Date(Date.parse('0001-01-01T00:00:00Z'))2000-12-31T23:00:00.000Z

EDIT: I'm looking for an explanation of why this behavior happens. I'm not looking for a fix, i know how to fix it.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>