倒數計時 Javascript count down
<script type='text/javascript'>
// 設定倒數日期
var countDownDate = new Date("Jan 1,
2023 00:00:00").getTime();
var x = setInterval(function() {
var
now = new Date().getTime();
var
distance = countDownDate - now;
var
days = Math.floor(distance / (1000 * 60 * 60 * 24));
var
hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var
minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var
seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("endSemester").innerHTML
= days + "天 " + hours + "小時 "
+
minutes + "分鐘 " + seconds + "秒 ";
if
(distance < 0) {
clearInterval(x);
document.getElementById("endSemester").innerHTML =
"新年快樂 ^_^";
}
}, 1000);
沒有留言:
張貼留言