shell_bug shell_bug - 17 days ago 8
Javascript Question

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

Why when I try to do so:

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


I get in output:

"11/20/2016"


Instead of:

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


Why I get next month in output?

Answer

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.