Js-ダイナミックフレーム時間カウントダウン
849 ワード
var timer = null;
window.onload = function() {
timer = setInterval(clock, 1000);
}
var c = document.getElementById("countdown");
function clock() {
var now = new Date();
//
var target = new Date("2999-1-25 3:00:00");
var time = (target - now) / 1000;
console.log(time)
if (time >= 0) {
var h = Math.floor(time / 60 / 60);
var m = Math.floor(time / 60 - (h * 60))
var s = Math.floor(time - (h * 60 * 60) - (m * 60))
h = h < 10 ? "0" + h : h
m = m < 10 ? "0" + m : m
s = s < 10 ? "0" + s : s
c.innerHTML = " " + h + " " + m + " " + s + " ";
} else {
clearInterval(timer);
timer = null;
c.innerHTML = "";
}
}