Vue.js:获取当前时间30天之前的日期

该方法获取日期的格式为YYYY-MM-DD

    getDay(day) {
      var today = new Date();
      var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
      today.setTime(targetday_milliseconds);
      
      var tYear = today.getFullYear();
      var tMonth = today.getMonth();
      var tDate = today.getDate();
      tMonth = this.doHandleMonth(tMonth + 1);
      tDate = this.doHandleMonth(tDate);
      return tYear + "-" + tMonth + "-" + tDate;
    },
    doHandleMonth(month) {
      var m = month;
      if (month.toString().length == 1) {
          m = "0" + month;
      }
      return m;
    }

获取当前日期30天之前的日期调用方式为:

getDay(-30);
posted @ 2022-12-05 09:22  新*  阅读(1288)  评论(0编辑  收藏  举报