<script>function countDown() {document.body.innerHTML = '';//清空页面内容var nowTimer = +new Date(); //现在时间的毫秒数var valueTimer = +new Date("2024-1-1 12:00"); //用户输入年份倒计时时间毫秒数var timer = (valueTimer - nowTimer) / 1000; //倒计时秒数var d = parseInt(timer / 60 / 60 / 24);d = d < 10 ? "0" + d : d;//天数少于十天前面加0(优化页面)var h = parseInt(timer / 60 / 60 % 24);h = h < 10 ? "0" + h : h;//小时少于十前面加0var m = parseInt(timer / 60 % 60);m = m < 10 ? "0" + m : m;//分钟少于十前面加0var s = parseInt(timer % 60);s = s < 10 ? "0" + s : s;//秒数少于十前面加0document.write(d + "天" + h + "时" + m + "分" + s + "秒");}countDown();setInterval(countDown, 1000);
</script>
现在时间为2023.11.30
离2024年还剩