Search code examples
jqueryjquery-countdown

Jquery countdown, 24hour and rules for weekends


Ive added the code in here When it hits friday after 11.00 it should countdown to money @ 11.00 Any suggestions / help to get here? Also: The CountDown-timer should also be able to check if its a holiday here in Denmark (not sure about this function, maybe a database to control that part, because the holidays will come in variables hmm?) http://jsfiddle.net/srwpyac0/24/

HTML:

<div id="countdown"></div>

JavaScript

function ShowTime() {
    var now = new Date();
    if (now.getHours() > 11) {
        var hrs = 11 - now.getHours() + 24;
    } else {
        var hrs = 11 - now.getHours();
    }
    var mins = 60 - now.getMinutes();
    var secs = 60 - now.getSeconds();

    timeLeft = "You now have " + hrs + ' Hour(s) ' + mins + ' minuts ' + secs + ' seconds' + " To complete the order, and make sure the delivery will reach to you in 1-3 days";
    $("#countdown").html(timeLeft);
}

var countdown;

function StopTime() {
    clearInterval(countdown);

}

setInterval(ShowTime, 1000);

Solution

  • I am not sure this is you want. Please check the code once.

    Javascript:

    function ShowTime() {
      var now = new Date();
        if (now.getHours() > 11){
            var hrs =11-now.getHours()+24;
            if(now.getDay() == 5){
                var hrs = hrs + 48;
            }
        }else{
      var hrs = 11-now.getHours();
             }
    
      var mins = 60-now.getMinutes();
      var secs = 60-now.getSeconds();
    
          timeLeft = "You now have "+hrs+' Hour(s) '+mins+' minuts '+secs+' seconds' +" To complete the order, and make sure the delivery will reach to you in 1-3 days";
      $("#countdown").html(timeLeft);
    }
    
    var countdown;
    function StopTime() {
        clearInterval(countdown);
    
    }
    
    setInterval(ShowTime ,1000);
    

    Fiddle : Fiddle