主体代码
<h1>距离全面建成现代化国家</h1>
<p></p>
<script>
function showTime() {
var nowTime = new Date().getTime();//获取当前时间
var endTime = new Date("2050-1-1 10:00:00").getTime();
var lineTime = (endTime - nowTime) / 1000;
var Year = parseInt(lineTime / 60 / 60 / 24 / 365);
Year = Year < 10 ? "0" + Year : Year
var Day = parseInt(lineTime / 60 / 60 / 24 % 365);
Day = Day < 10 ? "0" + Day : Day
var Hours = parseInt(lineTime / 60 / 60 % 24);
Hours = Hours < 10 ? "0" + Hours : Hours
var Minute = parseInt(lineTime / 60 % 60);
Minute = Minute < 10 ? "0" + Minute : Minute
var Second = parseInt(lineTime % 60);
Second = Second < 10 ? "0" + Second : Second
return "还剩余" + Year + "年" + Day + "天" + Hours + "时" + Minute + "分" + Second + "秒";
}
var p = document.querySelector("p");
setInterval(function () {
p.innerHTML = showTime();
}, 10);
</script>
css样式
h1 {
color: brown;
width: 800px;
text-align: center;
}
p {
text-align: center;
width: 800px;
font-size: 30px;
color: aqua;
}