www.webdeveloper.com
Results 1 to 2 of 2

Thread: Countdown every hour

Hybrid View

  1. #1
    Join Date
    Jun 2013
    Posts
    1

    Countdown every hour

    Hello,

    I've been searching for this on the internet but i can't find a similar script.

    I would like to count down to 10 seconds before a new hour starts, and that must loop every hour.
    For example, the scripts count down till 19:59:50 and than it will count till 20:59:50, and so on..

    Can someone help me with this?
    Thanks in advance!

    Niels

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Try this
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <title></title>
    <style type="text/css">
    #cnt {display:block;width:40px;text-align:center;line-height:40px;font-size:x-large;color:#fff;background-color:#000;}
    </style>
    </head>
    <body>
    <div id="pge"><p id="cnt"></p></div>
    <script type="text/javascript">
    
    var vigilancePeriod=15;
    function waitNewHour(){
        var tdy=new Date(),mnt=tdy.getMinutes(),scd=tdy.getSeconds(),dlt=3600-(mnt*60+scd);
    //    if (window.console) console.log("délai d'attente : "+dlt+" secondes");  
        if (vigilancePeriod<dlt) setTimeout(waitSecond,(dlt-vigilancePeriod)*1000);
        else waitSecond();
    }
    
    function waitSecond(){var tdy=new Date(),mnt=tdy.getMinutes(),scd=tdy.getSeconds(),dlt=3600-(mnt*60+scd);
    //    if (window.console) console.log("delta : "+dlt);
        if (dlt-10<=0) document.getElementById('cnt').innerHTML=dlt;
        if (vigilancePeriod<dlt) {document.getElementById('cnt').innerHTML='';waitNewHour();}
        else setTimeout(waitSecond,1000);
    }
    waitNewHour();
    </script>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles