let startTime = 1527647143949; // 开始时间
var time = new Countdown('timer',startTime);
function Countdown (el,startTime) {
this.startTime = startTime || '';
this.el = el || '';
// 轮询计算时间
this.loop = function () {
var that = this;
setInterval(function(){
that.init();
},1000);
};
// 格式化时分秒
this.formatDuring = function (mss) {
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
var seconds = parseInt((mss % (1000 * 60)) / 1000);
return hours + ": " + (minutes < 10 ? '0'+minutes : minutes) + ": " + (seconds < 10 ? '0'+seconds : seconds);
};
// 初始化倒计时
this.init = function () {
var endTime = this.startTime+(24*60*60*1000); // 结束时间
var timeLeft = endTime - new Date().getTime(); // 剩余时间
document.getElementById(this.el).innerHTML = this.formatDuring(timeLeft);
this.loop();
};
this.init();
};
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有