function createCalendar elem yy mm let len new Date yy mm getDate let

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function createCalendar(elem, yy, mm) {
let len = new Date(yy,mm,0).getDate();
let day = 2 - (new Date(yy, mm-1).getDay() || 7);
let ts = '<table><tr><th>Пн<th>Вт<th>Ср<th>Чт<th>Пт<th>Сб<th>Вс';
while(day <= len) {
ts += '<tr>';
for (let i=0; i<7; i++) {
ts += '<td>' + (day >= 1 && day <= len ? day : '');
day++;
}
}
elem.innerHTML = ts;
}