函數
function _getMonthWeek(theDate){
let currentDay = new Date(theDate);
console.info(currentDay); // 2019-05-07T07:36:00.883Z
// 獲取該日期所在周的週六,如2019.5月的週六有4號、11號、18號、25號、31號
let theSaturday = currentDay.getDate() + (6 - currentDay.getDay());
console.info(theSaturday); // 11
return Math.ceil(theSaturday / 7);
}
調用
let now = new Date();
console.info(now); // 2019-05-07T07:36:00.883Z
console.info(_getMonthWeek(now)); // 2 即2019年5月的第二週