js獲取多少天以後的時間

hql丶1024發表於2020-10-21
 // 獲取多少天后的時間
  getDateStr(today, addDayCount) {
    var dd;
    if (today) {
      dd = new Date(today);
    } else {
      dd = new Date();
    }
    dd.setDate(dd.getDate() + addDayCount); //獲取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m =
      dd.getMonth() + 1 < 10
        ? "0" + (dd.getMonth() + 1)
        : dd.getMonth() + 1;
    var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
    return y + "-" + m + "-" + d;
  },
},
created() {
  console.log(this.getDateStr("2020-10-22", 7));
  console.log(this.getDateStr(null, 7));
},

相關文章