0
매 시간마다 H- "시간 남음", 매분마다 M- "분 남음", 초 단위로 같은 시간을 표시하는이 타이머를 만들었습니다. 타임 스탬프 값에 따라 다릅니다. 당신은 단지 하나의 타이머를 필요새로 고침 타이머에서 H- "시간"에서 M- "분"으로 전환
window.onload = function() {
var actual_timestamp = Math.round((new Date()).getTime()/1000);
var time_remaining=<?php echo $vote_time_limit ?> - actual_timestamp;
var spanElt = document.getElementById('timer');
var h,m,s;
setInterval(function() {
//If time_remaining is between 24 and 1h, it decreases every hours
if(time_remaining<=86400 && time_remaining>=3600){
h=Math.floor(time_remaining/3600 % 24);
spanElt.innerHTML="H-"+h--;
time_remaining--;
}
} , 3600000);
setInterval(function() {
//If time_remaining is between 1h and 1min, it decreases every minutes
if(time_remaining<3600 && time_remaining>=60){
m=Math.floor(time_remaining/60 % 60);
spanElt.innerHTML="M-"+m--;
time_remaining--;
}
} , 60000);
setInterval(function() {
//If it is between 60sec and 0sec, it decreases every seconds
if(time_remaining<60 && time_remaining>0){
s=Math.floor(time_remaining % 60);
spanElt.innerHTML="S-"+s--;
time_remaining--;
//If time_remaining =0, it takes the value of the cycle time
}else if(time_remaining==0){
time_remaining=86400; //24h
}
} , 1000);
};
필자의 스크립트가 나쁘다고 생각했습니다. (하나의 setInterval만으로도 충분했습니다.) 도움을 주셔서 감사합니다. – Anon