2019-01-16 | 倒计时功能 | UNLOCK

倒计时功能

1
2
3
4
5
6
<div class="time1">还剩时间:
<span id="1"></span>
<span id="2"></span>
<span id="3"></span>
<span id="4"></span>
</div>
1
2
3
4
5
.time1 span {
display: inline-block;
width: 40px;
height: 20px;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function show(times) {
var time = Number(new Date(times));
// var time=new Date(myyear,mymonth,myday,myhour,myminute,mysecond).getTime();
//获取当前时间
var nowTime = Date.now();
// var nowTime=new Date().getTime();
//获取时间差
var timediff = Math.round((time - nowTime) / 1000);
if (timediff <= -1) {
return;
}
//获取还剩多少天
var day = parseInt(timediff / 3600 / 24);
//获取还剩多少小时
var hour = parseInt(timediff / 3600 % 24);
//获取还剩多少分钟
var minute = parseInt(timediff / 60 % 60);
//获取还剩多少秒
var second = timediff % 60;
//输出还剩多少时间
document.getElementById("1").innerHTML = day;
document.getElementById("2").innerHTML = hour;
document.getElementById("3").innerHTML = minute;
document.getElementById("4").innerHTML = second;
setTimeout(show, 1000);

}
show("2019-1-8 17:33:0")

评论加载中