js Get the date in the next 7 days

Get the next 7 days date

const dateArray = [];
for (let i = 0; i < 7; i++) {
    
    
  const date = new Date(Date.now() + i * 24 * 60 * 60 * 1000);
  const year = date.getFullYear();
  const month = date.getMonth() + 1 < 10 ? `0${
      
      date.getMonth() + 1}` : date.getMonth() + 1;
  const day = date.getDate() < 10 ? `0${
      
      date.getDate()}` : date.getDate();
  dateArray.push(`${
      
      year}-${
      
      month}-${
      
      day}`);
}
console.log(dateArray);

Guess you like

Origin blog.csdn.net/weixin_43483746/article/details/129787776