JSFiddle - React, Tailwind, and code Playground
JavaScript
// find all dates that fall on a particular day of the week
// for the given year and month
function getDaysOfMonth(year, month, dow) {
--month; // to correct for JS date functions
var d = new Date(year, month, 1); // get the first of the month
var dow_first = d.getDay(); // find out what DoW that was
var date = (7 + dow - dow_first) % 7 + 1; // and hence the first day matching dow
var dates = [];
d.setDate(date);
do {
dates.push(new Date(d)); // store a copy of that date
date += 7; // go forward a week
d.setDate(date);
} while (d.getMonth() === month); // until the end of the month
return dates;
}
document.write(getDaysOfMonth(2011, 12, 5).join("<br>"));