/**
* 国内自然周
*/
const getWeekOfNature=(date,format)=>{
let weekOfday = moment(date).format("E"); //计算是这周第几天
let monday = moment(date).subtract(weekOfday - 1, "days"); //获取周一
let sunday = moment(date).add(7 - weekOfday, "days"); // 获取周日
return {
week:moment(monday).format("WW"),
startDate: format ?monday.format(format): monday,
endDate:format ?sunday.format(format): sunday,
}
}
console.log(getWeekOfNature('2022-10-07','YYYY-MM-DD')) // {week: '40', startDate: '2022-10-03', endDate: '2022-10-09'}