获取最近三天或者一星期的时间和周

图片

获取最近三天或者一星期的时间和周_第1张图片

代码

dateTabs() {

      let now = new Date();

      let nowTime = now.getTime();

      const oneDayTime = 24 * 60 * 60 * 1000;

      let arr = [];

      for (var i = 0; i < 7; i++) {

        let ShowTime = nowTime + i * oneDayTime;

        let myDate = new Date(ShowTime);

        let year = myDate.getFullYear();

        let month = myDate.getMonth() + 1;

        let date = myDate.getDate();

        if (0 <= month <= 9) {

          month = "0" + month;

        }

        if (0 <= date <= 9) {

          date = "0" + date;

        }

        let obj = {};

        obj.id = i;

        obj.date = month + "-" + date;

        obj.weekDay = "周" + "日一二三四五六".charAt(myDate.getDay());

        arr.push(obj);

      }

      this.days = arr;

    },

你可能感兴趣的:(获取最近三天或者一星期的时间和周)