2

When initializing a new Date instance in Chrome, if the provided value is a partial date string (with no year set), Chrome defaults the Year to 2001. This behavior is different than other browsers such as Firefox, which returns "Invalid Date" in such case.

For example: new Date('05/22') will result to May 22, 2001

Is there any specific reason they use 2001 as the default year and not the current year? Is there any way to change this behavior?

Hadas
  • 91
  • 6
  • 3
    Possible duplicate of [Why does Date.parse give incorrect results?](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – Rajesh Nov 20 '17 at 09:18
  • Can you show an example of how you're actually initialising it? – James Thorpe Nov 20 '17 at 09:18
  • 1
    I had asked the same question long time back. You can check this as well: https://stackoverflow.com/questions/40504116/default-year-in-date-if-datestring-does-not-have-year-part – Rajesh Nov 20 '17 at 09:18
  • @JamesThorpe You can try `new Date('11/20')`. I have a snippet in my related post. You can even check that. – Rajesh Nov 20 '17 at 09:19

0 Answers0