js倒计时
标签:
JavaScript
<!--倒计时-->
window.onload = clock;
function clock() {
//获取结束的时间戳
var timestamp = $("#shijiancuo").attr("title");
//根据时间戳生成的时间对象
var stop = new Date(timestamp * 1000);
//获取当前时间
var today = new Date();
//剩余时间
var shenyu = stop.getTime() - today.getTime(),//倒计时毫秒数
shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)),//转换为天
D = parseInt(shenyu) - parseInt(shengyuD * 60 * 60 * 24 * 1000),
shengyuH = parseInt(D / (60 * 60 * 1000)),//转换为小时
H = D - shengyuH * 60 * 60 * 1000,
shengyuM = parseInt(H / (60 * 1000)),//转换为分钟
M = H - shengyuM * 60 * 1000;
shengyuS = parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - shengyuH * 60 * 60 * 1000 - shengyuM * 60 * 1000) / 1000);//转换为秒
//小于 10 的时候在前面加 0
if (shengyuS < 10) {
shengyuS = "0" + shengyuS
} else {
shengyuS
}
if (shengyuH < 10) {
shengyuH = "0" + shengyuH
} else {
shengyuH
}
if (shengyuM < 10) {
shengyuM = "0" + shengyuM
} else {
shengyuM
}
if (shengyuD < 10) {
shengyuD = "0" + shengyuD
} else {
shengyuD
}
document.getElementById("time1").innerHTML = shengyuD;
document.getElementById("time2").innerHTML = shengyuH;
document.getElementById("time3").innerHTML = shengyuM;
document.getElementById("time4").innerHTML = shengyuS;
setTimeout("clock()", 500);
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦