<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<style>
#con {
width: 500px;
height: 200px;
border: 2px solid fuchsia;
margin: 30px auto;
}
#con1 {
width: 500px;
height: 100px;
line-height: 100px;
font-size: 20px;
}
#con2 {
width: 500px;
height: 100px;
line-height: 100px;
font-size: 30px;
color: darkturquoise
}
</style>
</head>
<body>
<div id="con">
<div id="con1">距离过年还剩:</div>
<div id="con2"></div>
</div>
<script>
var con, con1, con2;
con = document.getElementById("con")
con1 = document.getElementById("con1")
con2 = document.getElementById("con2")
function auto() {
var time
time = new Date()
newtime = new Date(2020, 0, 30)
tt = newtime.getTime() - time.getTime()
console.log(tt)
day = Math.floor(tt / 1000 / 60 / 60 / 24)
hours = Math.floor((tt - day * 24 * 60 * 60 * 1000) / 1000 / 60 / 60)
minutes = Math.floor((tt - day * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60)
seconds = Math.floor((tt - day * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000)
millioseconds = Math.floor((tt - day * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000 - seconds * 1000))
//console.log(day+"天"+hours+"小时"+minutes+"分"+seconds+"秒")
con2.innerHTML = day + "天" + hours + "小时" + minutes + "分" + seconds + "秒" + millioseconds + "毫秒"
// console.log( time.getTime()/1000/60/60/24/365)
}
setInterval(auto, 1)
</script>
</body>
</html>