js根据当前日期获取本周的日期

function getDates() {
    var new_Date = new Date()
    var timesStamp = new_Date.getTime();
    var currenDay = new_Date.getDay();
    var dates = [];
    for(var i = 0; i < 7; i++) {
        dates.push(new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - (currenDay + 6) % 7)).toLocaleDateString().replace(/[年月]/g, '-').replace(/[日上下午]/g, ''));
    }
    return dates
}

console.log(getDates())

你可能感兴趣的:(js根据当前日期获取本周的日期)