封装成promise 首先传参,传入一个以当前时间为基准n个小时后的时间,声明一个变量获取当前时间,
wishingCountDown(eve) {
return new Promise((rel, rej) => {
let data = new Date()
let time = data.getTime() //当前时间
if (eve - time > 0) {
let surplus = (eve - time) //他们之间的时间戳
let days = Math.floor(surplus / (1000 * 60 * 60 * 24)) //天的时间戳
let hours = Math.floor((surplus % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); //小时戳
let minutes = Math.floor((surplus % (1000 * 60 * 60)) / (1000 * 60)); //分钟的时间戳
let seconds = Math.floor((surplus % (1000 * 60)) / 1000); //秒的时间戳
function part(val) {
var lenval = (val + '').length;
if (lenval >= 2) {
return val;
} else {
return '0' + val;
}
}
console.log();
this.wishingDays = days
// this.wishingHours
var wishingHour1 = hours;
this.wishingHours = pa