根據開始時間和結束時間實現倒計時效果


    getDate() {
      var time_now_server, time_now_client, time_end, time_server_client;
      time_end = new Date("2020 07 22 18:50:50");//結束的時間
      time_end = time_end.getTime();
      time_now_server = new Date("2020 07 21 16:35:35");//開始的時間
      time_now_server = time_now_server.getTime();
      time_now_client = new Date();
      time_now_client = time_now_client.getTime();
      time_server_client = time_now_server - time_now_client;
      var timeFunction = () => {
        var time_now, time_distance, str_time;
        var time_now = new Date();
        time_now = time_now.getTime() + time_server_client;
        time_distance = time_end - time_now;
        if (time_distance > 0) {
          this.day = Math.floor(time_distance / 86400000)
          time_distance -= this.day * 86400000;
          this.h = Math.floor(time_distance / 3600000)
          time_distance -= this.h * 3600000;
          this.m = Math.floor(time_distance / 60000)
          time_distance -= this.m * 60000;
          this.s = Math.floor(time_distance / 1000)
          if (this.h < 10)
            this.h = "0" + this.h;
          if (this.m < 10)
            this.m = "0" + this.m;
          if (this.s < 10)
            this.s = "0" + this.s;
        } else {
          clearInterval(go);
        }
      }
      timeFunction();
      let go = setInterval(function () {
        timeFunction();
      }, 1000);
    },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM