jsClock – JavaScript Clock with few options
I needed a Clock that is updating automatically and takes the time from the server (same as the office), also they want to display the time in other countries to have a reference.
For this I developed a “simple” (how much I like this word) script to update times.
Installation:
Download, unzip and serve your self!
UPDATE: Faster way, just copy paste this in your site:
<script type='text/javascript' src='http://lab.neo22s.com/jsClock/jsClock.js'></script> <link rel="stylesheet" href="http://lab.neo22s.com/jsClock/jsClock.css" type="text/css" /> <div id="rellotje" class="clock"></div> <script type='text/javascript'>moveClock("rellotje");</script>
Usage:
This is the main function that is calling her self all time.
function moveClock(idClock,startTime){//move given clock var timeout=1000;//miliseconds to repeat the function if ( startTime === undefined ) {//just take the browser time rightNow = new Date(); hour = rightNow.getHours(); minute = rightNow.getMinutes(); second = rightNow.getSeconds(); } else{//starttime set rightNow = startTime.split(':',3); hour = parseInt(rightNow[0],10); minute = parseInt(rightNow[1],10); second = parseInt(rightNow[2],10); if (second==59){ if (minute==59){ if (hour==23) hour=0; else hour++; minute=0; }else minute++; second=0; }else second++; } if (minute<10) minute= "0" + minute; if (second<10) second= "0" + second; currentTime=hour + ":" + minute + ":" +second;// tim to return document.getElementById(idClock).innerHTML = currentTime;//tim for the HTML element //recursivity if (startTime===undefined) setTimeout("moveClock('"+idClock+"')",timeout);//browser time else setTimeout("moveClock('"+idClock+"','"+currentTime+"')",timeout);//set time }
To use it is really easy:
Normal clock using browser time:
<div id="clock" >clock</div> <script type='text/javascript'> moveClock("clock"); </script>
Clock with manual time: (you can write it or use php or asp or whatever you want)
<div id="clock">clock</div>
<script type='text/javascript'>
moveClock("clock",<?php echo date("G:i:s");?>);
</script>You can also run several clocks in the same site same time ;)
Version: 0.1
Author: Chema Garrido
License: GPL v3
Support: forum.neo22s.com
Notes:
Works in FF 3.5, Chromium, ie6
