js 倒计时

/**
* 启动,秒杀倒计时. time格式:DDHH24MISS 例如: time="11223344";
*
*/
function timer(time) {
var d = time.substring(0, 2);
var h = time.substring(2, 4);
var m = time.substring(4, 6);
var s = time.substring(6, 8);
// 计算剩余秒杀
var totalSecond = parseInt(d * 86400) + parseInt(h * 3600)
+ parseInt(m * 60) + parseInt(s);
var secSkillTimeInterval = "";
secSkillTimeInterval = setInterval(function(totalSecond) {
return function() {
if (totalSecond <= 0) {
clearInterval(secSkillTimeInterval);
}
var mss = totalSecond * 1000;
var tm = {
day : parseInt(mss / (1000 * 60 * 60 * 24)),
hour : parseInt((mss % (1000 * 60 * 60 * 24))
/ (1000 * 60 * 60)),
min : parseInt((mss % (1000 * 60 * 60)) / (1000 * 60)),
second : parseInt((mss % (1000 * 60)) / 1000)
}
showTime(tm);
--totalSecond;
}
}(totalSecond), 1000);
}

// 显示秒杀倒计时
function showTime(tm) {
var msg = tm.day + "天" + tm.hour + "时" + tm.min + "分" + tm.second + "秒";
console.log(msg);
}

上一篇:微信touchmove不生效


下一篇:破解C#反编译软件Reflector 11.1.0.2167(最新版)(附补丁下载)