An easy and fast way to develope a clock that is updated every minute:
<div class="clock"> <i class="fa fa-clock-o"> </i><span>15:51</span><script type="text/javascript"> var intervalclock = 0; function startClock() { setTimeout(function() { print_clock(); intervalclock = 60; setInterval(function() { print_clock(); }, intervalclock * 1000); }, intervalclock * 1000); } function print_clock() { var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); if (minute < 10) { minute = "0" + minute; }; var timeString = hour + ':' + minute; $('.clock\ > span').text(timeString); } $(window).load(function() { var timeclock = new Date(); intervalclock = 60 - timeclock.getSeconds(); if(intervalclock == 60) { intervalclock = 0; } startClock(); }); </script> </div>
Best regards!
No comments:
Post a Comment