.getDay() strange behaviour

javascript

Solution

When setting the date, passing 2 means March as it is 0 based. If you use 1 for february it will work as expected.

Quoting https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date

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

Problem

There is an example ``` console.log((new Date(2013, 02, 24)).getDay(), 24) // => 0 24 console.log((new Date(2013, 02, 25)).getDay(), 25) // => 1 25 console.log((new Date(2013, 02, 26)).getDay(), 26) // => 2 26 console.log((new Date(2013, 02, 27)).getDay(), 27) // => 3 27 console.log((new Date(2013, 02, 28)).getDay(), 28) // => 4 28 console.log((new Date(2013, 03, 01)).getDay(), 01) // => 1 1 console.log((new Date(2013, 03, 02)).getDay(), 02) // => 2 2 ``` According to https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/getDay, method `getDay()` Returns the day of the week for the specified date according to local time. The value returned by getDay is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on. It doesn't seem to be true for the two last results. I expect the output to be like the following ``` 0 24 1 25 2 26 3 27 4 28 5 1 6 2 ``` Am I missing something?

Original source

Related problems