JSFiddle - React, Tailwind, and code Playground

by Sinh Nguyen

JavaScript

const now = new Date();
var days =  getDaysInMonth(now.getMonth(),now.getFullYear());
for ( let i = 0; i < days.length; i ++) {
	console.log(days[i].getMonth(), days[i].getDate());
}
function getDaysInMonth(month, year) {

  var date = new Date(year, month, 1);
  var days = [];
  while (date.getMonth() === month) {
    var tmp = new Date(date) 
    console.log('tmp', tmp.getMonth(), tmp.getDate());
    days.push(tmp);
    date.setDate(date.getDate() + 1);
  }
  console.log('days', days.length)
  console.log('month-year', month, year)
  return days;
}