首页 > 代码库 > 根据传入的年份和月份获取该月属于本年的第几周和每周的开始和结束日期

根据传入的年份和月份获取该月属于本年的第几周和每周的开始和结束日期

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;                    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‘);

 

根据传入的年份和月份获取该月属于本年的第几周和每周的开始和结束日期