jsでカウントダウン効果を実現します.
1348 ワード
, “×× ×× ×× ×× ×× ”。
//
var isTime = new Date('2018-06-7 00:00:00');
var isMillis = isTime.getTime() - new Date().getTime();
var showTime = document.getElementById('showTime');
if(isMillis > 0) {
//
function datetime() {
isMillis = isTime.getTime() - new Date().getTime();
var tian = Math.floor(isMillis / 1000 / 60 / 60 / 24);
if(tian < 10) {
hours = '0' + hours;
}
var hours = Math.floor((isMillis - tian * 24 * 60 * 60 * 1000) / 1000 / 60 / 60);
if(hours < 10) {
hours = '0' + hours;
}
var minutes = Math.floor((isMillis - tian * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60);
if(minutes < 10) {
minutes = '0' + minutes;
}
var seconds = Math.floor((isMillis - tian * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000);
if(seconds < 10) {
seconds = '0' + seconds;
}
showTime.innerHTML = tian + ' ' + hours + ' ' + minutes + ' ' + seconds + ' ';
}
datetime();
} else {
document.write(' !')
}
// ,
setInterval(datetime, 1000);