-1

I'm trying to get the day of the week from a manually set date.

var year = 2017;
var month = 10;
var d = new Date(year, month, 1);
var n = d.getDay();
console.log(n);

The above outputs 3, however, the correct day of the 1st of October is Sunday (ie. day 6 in JS terms). What am i doing wrong?

Mike Hawkins
  • 2,144
  • 5
  • 24
  • 42

2 Answers2

1

In javascript months start from 0. So your date is not really 1st of October, it is 1st of November, which is Wednesday.

plmn
  • 46
  • 3
1

In JavaScript, dates are denoted by the numbers 0-11 (like an array). So October would be 9. Your program is getting the 1st of November, which is a Wednesday.

Gladdstone
  • 72
  • 7