Day of next or previous month
Let's find out the day of the week on the first of the previous month. To do this, subtract one from the current month:
let now = new Date();
let date = new Date(now.getFullYear(), now.getMonth() - 1, 1);
console.log(date.getDay());
Question: will there be a problem if
the current month is January? After
all, it has the number 0
, and
when subtracting one from it, we get
minus the first month.
Determine what day of the week was a month ago on the same day of the month as today.