倒计时方法

vm.getTimeCountDown = function(data, that) {

var endTime = new Date(data),

nowTime = new Date();

if(endTime.getTime() >= nowTime.getTime()) {

var countTime = endTime.getTime() - nowTime.getTime();

} else {

clearInterval(that);

};

d = 0, h = 0, m = 0, s = 0;

if(countTime >= 0) {

var countTimeData = {

d: Math.floor(countTime / 1000 / 60 / 60 / 24),

h: Math.floor(countTime / 1000 / 60 / 60),

m: Math.floor(countTime / 1000 / 60 % 60),

s: Math.floor(countTime / 1000 % 60)

};

return timeStr = _formatTimeNum(countTimeData.h) + ':' + _formatTimeNum(countTimeData.m) + ':' + _formatTimeNum(countTimeData.s);

}

function _formatTimeNum(timeNum) {

if(timeNum < 10) {

return "0" + timeNum;

}

return timeNum;

}

};

var that = $interval(function() {

vm.getTimeCountDown()

}, 1000)

你可能感兴趣的:(倒计时方法)