根据开始时间和结束时间实现倒计时效果
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);
},