2013-06-13 1 views
0

내 마음이 공백이라면 도움이 될 것입니다. 초를 제거하면 매분 (좋은 상태)으로 업데이트되지만 초를 사용하여지기를 원하지 않습니다. (초와.) 새로 고침에 업데이트 귀하의 setInterval을 함수는 같은 countDown을 참조하지 않아야이 타이머를 실시간 (자바 스크립트)으로 업데이트하려면 어떻게해야합니까?

var stopYear = 2013; /* the year (YYYY) to stop the count down */ 
var stopMonth = 7; /* the month (1-12) that we stop the count down */ 
var stopDay  = 14; /* the day of the month (1-31) that we stop the count down */ 
var stopHour = 17; /* the number of hours (0-23) that we stop the count down*/ 
var stopMins = 30; /* the number of minutes (0-59) that we stop the count down */ 
var stopSeconds = 0; /* the number of seconds (0-59) that we stop the count down */ 

/* build up the date that we are to stop the count down into a single date object */ 
var stopDate = new Date(); 
stopDate.setFullYear(stopYear,stopMonth-1,stopDay); 
stopDate.setHours(stopHour,stopMins,stopSeconds); 

function countDown() { 
    var _milliseconds = stopDate - new Date(); 
    var _days = Math.round(_milliseconds/(86400000)); 
    _milliseconds = _milliseconds % (86400000); 
    var _hours = Math.round(_milliseconds/(3600000)); 
    _milliseconds = _milliseconds % (3600000); 
    var _minutes = Math.round(_milliseconds/(60000)); 
    _milliseconds = _milliseconds % (60000); 
    var _seconds = Math.round(_milliseconds/(1000)); 
    var countDownText = 'The show is being played right now!'; 

    if (_minutes > 0) { 
     _hours==24 ? _days= _days+1: _days=_days; 
     _hours==24 ? _hours=0: _hours = _hours;//gm 
     countDownText = _days + ' Day' + (_days!=1 ? 's ' : ' '); 
     countDownText += _hours + ' hour' + (_hours!=1 ? 's and ' : ' and '); 
     countDownText += _minutes + ' minute' + (_minutes!=1 ? 's ' : ' '); 
     countDownText += _seconds + ' seconds' + (_seconds!=1 ? 's ' : ' '); 
     countDownText += '.'; 
    } else { 
     if (countDownHandle) clearInterval(countDownHandle); 
    } 
    document.getElementById('timeSenyu').innerHTML = countDownText; 
} 

var countDownHandle = null; 
function startCountDown() { 
    countDown(); 
    countDownHandle = setInterval('countDown()',60000); 
} 
onload = startCountDown; 
+0

UTC로 작업해야 클라이언트가 다른 시간대에있을 수 있습니다. "이 날짜까지 다시 돌아갈 것입니까?"라는 의미는 무엇입니까? –

답변

0

. 시도하십시오 setInterval(countDown, 60000).

+0

카운트 다운되지만 사용자는 카운트 다운을 볼 수 없습니다. 어떻게 가능할까요? – user1043816

+0

모든 관련 코드 (HTML/CSS/JS)로 JSFiddle을 만들 수 있습니까? – Seiyria

관련 문제