shell_bug shell_bug - 1 year ago 83
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download