
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1 id="time"></h1>
<script type="text/javascript">
window.onload =function () {
function timer() {
var minusTime = (new Date(2017,11,31,23,0,0)) - (new Date());
var days = parseInt(minusTime / 86400000);
var hours = parseInt((minusTime % 86400000) / 3600000);
var minutes = parseInt((minusTime % 3600000) / 60000);
var seconds = parseInt((minusTime % 60000) / 1000);
function checkTime(i) {
if (i < 10) {
return '0' + i;
}else {
return i;
}
}
days = checkTime(days);
hours = checkTime(hours);
minutes = checkTime(minutes);
seconds = checkTime(seconds);
document.getElementById('time').innerHTML = days + "天 " + hours + ":" + minutes + ":" + seconds;
}
timer();
setInterval (timer,1000);
}
</script>
</body>
</html>