shell_bug shell_bug - 8 months ago 48
Javascript Question

Why I get incorrect output of d.toLocaleDateString()?

Why when I try to do so:

var d = new Date(2016, 10, 20)

I get in output:


Instead of:

"10/20/2016" // as in new Date(2016, 10, 20)

Why I get next month in output?


The month argument value starts from 0 so it's expected behaviour.

From MDN docs - description of month argument :

Integer value representing the month, beginning with 0 for January to 11 for December.