js 获取当天下周3天的时间日期

const day = new Date()
        const myday = day.getDay()
        const current =day.getTime();
        const list = []
        // 获取到下周3的天数
        let  offset  = 7 - myday + 3
        // 获取到下周3,4,5的天数
        for (let i = 0; i < 3; i++) {
          list.push( offset + i)
        }            
        const listday = []
        // 循环出这3天的getTime,转化成日期
        for (const item of list) {
          let times = current +item* 24 * 3600 * 1000
          times= new Date(times);
          const futureYear = times.getFullYear();
          const futureMonth = times.getMonth() + 1;
          const futureDate  = times.getDate();     
          futureDate = futureDate < 10 ? '0' + futureDate : futureDate.toString(); // 如果日期小于10则补个0
          console.log(futureYear+'-'+futureMonth+'-'+futureDate);
          listday.push(futureYear+'-'+futureMonth+'-'+futureDate)
        }
        console.log(listday);

你可能感兴趣的:(js 获取当天下周3天的时间日期)