//获取当前是今年的多少周
function getYearWeek() {
var nowDate = new Date();
console.log(nowDate)
var nowYear = nowDate.getFullYear();//年
var nowMonth = nowDate.getMonth();
var nowDay = nowDate.getDate();
console.log(nowYear+"年"+((nowMonth*1)+1)+"月"+nowDay+"日")
/*
now_date是当前日期
one_date是当年第一天
d是当前日期是今年第多少天
用d + 当前年的第一天的周差距的和在除以7就是本年第几周
*/
var now_date = new Date(nowYear, nowMonth, nowDay),one_date = new Date(nowYear, 0, 1),
d = Math.round((now_date.valueOf() - one_date.valueOf()) / 86400000);//24*60*60*1000
console.log("d",d)
var weeks = Math.ceil((d + one_date.getDay()) / 7);
console.log(weeks)
}
01-10
1111
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-30
528
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)