vue项目时间倒计时

一、年月日,时分秒

mounted() {
    this.getTime();
    this.getMonthData();
    setInterval(() => {
      this.getTime();
    }, 60000);
},
methods: {
    getTime() {
      // this.roadMap();
      var a = ["日", "一", "二", "三", "四", "五", "六"];
      var weeker = new Date().getDay();
      this.week = "星期" + a[weeker];

      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      const hh = (time.getHours() + "").padStart(2, "0");
      const mm = (time.getMinutes() + "").padStart(2, "0");
      const ss = (time.getSeconds() + "").padStart(2, "0");
      this.getData = `${y}-${m}-${d}`;


      this.getMinutes = `${hh}:${mm}:${ss}`;
    },
}

二、倒计时天

data(){

return{
      starttime: "2020 / 05 / 01",
      // 倒计时
      date: "",

      // 完工时间
      endtime: "2020 / 08 / 31",
}},
methods: {
    countDown() {
      // 开工时间
      var startDate = Date.parse(this.getTimeimg);
      // 完工时间
      var endDate = Date.parse(this.endtime);
      var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
      // alert(days);
      // return days;
      this.date = days;
      // console.log(this.date);
    }
}

你可能感兴趣的:(vue项目时间倒计时)