function createProcess(year, month) { var calendar = "<table><tr class='dayOfWeek'>"; for (var i = 0; i < week.length; i++) { calendar += "<th>" + week[i] + "</th>"; } calendar += "</tr>"; var count = 0; var startDayOfWeek = new Date(year, month, 1).getDay(); var endDate = new Date(year, month + 1, 0).getDate(); var lastMonthEndDate = new Date(year, month, 0).getDate(); var row = Math.ceil((startDayOfWeek + endDate) / week.length); for (var i = 0; i < row; i++) { calendar += "<tr>"; // 1colum for (var j = 0; j < week.length; j++) { if (i == 0 && j < startDayOfWeek) { calendar += "<td class='disabled'>" + (lastMonthEndDate - startDayOfWeek + j + 1) + "</td>"; } else if (count >= endDate) { count++; calendar += "<td class='disabled'>" + (count - endDate) + "</td>"; } } calendar += "</tr>"; } return calendar; }