第一天日期为周一,最后一天为周日
//weekNum:第几周,year:年份
function getFromWeekNum(weekNum, year) {
const startTimes = new Date(year, 0, (2 + (weekNum - 1) * 7));
const endTimes = new Date(year, 0, (8 + (weekNum - 1) * 7));
return {
//.replace(/(\/)/g,'-')把所有“/”替换成“-”
startTimes: startTimes.toLocaleDateString().replace(/(\/)/g,'-'),//toLocaleDateString()把Date对象的日期部分转换为字符串,并返回结果
endTimes: endTimes.toLocaleDateString().replace(/(\/)/g,'-')
};
}