This is a wrong forum, but since I bothered to look this up...

Marfaba Stewart <[email protected]> writes:

> In the Firefox console
>
> new Date(2021,12,31) I see
> "Date Mon Jan 31 2022 00:00:00 GMT -600 (CST)
>
> but new Date(2021,12,31).toLocaleDateString() yields
> "1/30/2022"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
has this to say:

new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, 
milliseconds]]]]])
...
monthIndex
  Integer value representing the month, beginning with 0 for January to 11 for 
December.

12 is out of range and so behaves unexpectedly.

> so it appears the day of the month has been decremeted
> from 31 to 30.
>
> This happens for me in any tab unless I open the
> Preferences tab. In that tab, in the console output,
> I get the expected
> "1/31/2022"

AFAICT, chrome behaves identically:

> new Date(2021,12,31)
Mon Jan 31 2022 00:00:00 GMT-0800 (Pacific Standard Time)
> new Date(2021,12,31).toLocaleDateString()
"1/31/2022"

Thanks
Greg

Reply via email to