Countdown ultilizing the current time in Javascript

Asked

Viewed 765 times

1

Guys I found this counter in Javascript on the internet and I need to configure it as follows:

In giving 22 hours he starts the countdown, the countdown goes to 15 hours the next day, then the day after giving 22 hours again, It will start again and so on, only I do not know how to configure it because I do not understand anything Javascript, if someone can give a strength there, I thank you already. Follows the code:

function getTimeRemaining(endtime){
    var t = Date.parse(endtime) - Date.parse(new Date());
    var seconds = Math.floor( (t/1000) % 60 );
    var minutes = Math.floor( (t/1000/60) % 60 );
    var hours = Math.floor( (t/(1000*60*60)) % 24 );
    var days = Math.floor( t/(1000*60*60*24) );
    return {
        'total': t,
        'days': days,
        'hours': hours,
        'minutes': minutes,
        'seconds': seconds
    };
}

function initializeClock(id, endtime){
    var clock = document.getElementById(id);
    var daysSpan = clock.querySelector('.days');
    var hoursSpan = clock.querySelector('.hours');
    var minutesSpan = clock.querySelector('.minutes');
    var secondsSpan = clock.querySelector('.seconds');

    function updateClock(){
        var t = getTimeRemaining(endtime);

        daysSpan.innerHTML = t.days;
        hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
        minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
        secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);

        if(t.total<=0){
            clearInterval(timeinterval);
        }
    }

    updateClock();
    var timeinterval = setInterval(updateClock,1000);
}

var deadline = 'December 31 2015 00:00:50 UTC+0200';
initializeClock('clockdiv', deadline);
<div id="clockdiv">
  <span class="days"></span>
  <span class="hours"></span>
  <span class="minutes"></span>
  <span class="seconds"></span>
</div>

  • 2

    http://answall.com/q/92691/4808

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.