function getInfo(year, month) { var getInfo = function (year, month) { var d = new Date(); d.setFullYear(year, month - 1, 1); var w1 = d.getDay(); if (w1 == 0) w1 = 7; d.setFullYear(year, month, 0); var dd = d.getDate(); if (w1 != 1) { var d1 = 7 - w1 + 2; } else { d1 = 1; } var week_count = Math.ceil((dd - d1 + 1) / 7); for (var i = 0; i < week_count; i++) { var monday = d1 + i * 7; var sunday = monday + 6; if (monday < 10) { monday = (Array(2).join(0) + monday).slice(-2); } if (sunday < 10) { sunday = (Array(2).join(0) + sunday).slice(-2); }//此处是为了获取的日期中的日如果小10前边的0会自动消失的处理 var from = year + "/" + month + "/" + monday; var to; if (sunday <= dd) { to = year + "/" + month + "/" + sunday; } else { d.setFullYear(year, month - 1, sunday); to = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate(); } var d11 = new Date(year + "-" + month + "-" + monday); var d2 = new Date(year + "-" + month + "-" + monday); d2.setMonth(0); d2.setDate(1); var rq = d11 - d2; var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000)); var s2 = Math.ceil(s1 / 7); console.log("第" + s2 + "周(" + from + " 到 " + to + ")" ); } }; } getInfo('2013','12');