js获取几天前的日期

getTime(diff) {
      var nowdate = new Date()
      if (diff) {
        nowdate.setDate(nowdate.getDate() + diff)
      }
      var year = nowdate.getFullYear()
      var month = nowdate.getMonth() + 1 < 10 ? '0' + (nowdate.getMonth() + 1) : nowdate.getMonth() + 1
      var day = nowdate.getDate() < 10 ? '0' + nowdate.getDate() : nowdate.getDate()
      return year + month + day
    }

 

posted @ 2022-03-01 09:53  仓鼠爱画方格子  阅读(719)  评论(0编辑  收藏  举报