JS倒计时每天2次

时间:2013-02-24 10:26:37

标签: countdown

我希望计时器倒计时到凌晨2:10,然后倒计时到下午2:10 每天。 我希望你明白我的意思。

可以吗?

谢谢:)

P.S。我尝试过这个,但这只是一个时间而不是2:

    function getSeconds() {
        var now = new Date();
        var time = now.getTime();  
        // time now in milliseconds
        var midnight = new Date(now.getFullYear(),now.getMonth(),now.getDate(),12,0,0); 
        // midnight 0000 hrs
        // midnight - change time hh,mm,ss to whatever time required, e.g. 7,50,0 (0750)
        var ft = midnight.getTime() + 86400000;  // add one day
        var diff = ft - time;  
      diff = parseInt(diff/1000);
      if (diff > 86400) {diff = diff - 86400}
      startTimer (diff);
    }
    var timeInSecs;
    var ticker;
    function startTimer(secs){
        timeInSecs = parseInt(secs);
        ticker = setInterval("tick()",1000); 
        tick(); // to start counter display right away
    }
    function tick() {
        var secs = timeInSecs;
      if (secs>0) {
        timeInSecs--;
    }
    else {
        clearInterval(ticker); // stop counting at zero
        //getSeconds();  // and start again if required
    }
    var hours= Math.floor(secs/3600);
    secs %= 3600;
    var mins = Math.floor(secs/60);
    secs %= 60;
    var result = ((hours < 10 ) ? "0" : "" ) + 
                    hours + " hours " + ( (mins < 10) ? "0" : "" ) + mins
                      + " minutes " + ( (secs < 10) ? "0" : "" ) + secs + " seconds";
    var text = "The next update of this site will be in ";
    document.getElementById("countdown").innerHTML = text + result;
    }

0 个答案:

没有答案