How to make a clock using javascript

How to make a clock using javascript

A few lines of javascript is required to make a clock. It shows the local time( the time that is displayed in your Computer).

Javascript Code

<script type="text/javascript">
function ShowTime(ctrl)
{
  var time=new Date();
  var h=time.getHours();
  var m=time.getMinutes();
  var s=time.getSeconds();
  // add a zero in front of numbers<10
  m=checkTime(m);
  s=checkTime(s);
  var obj = document.getElementById(ctrl);
  obj.innerHTML=h+" : "+m+" : "+s;
  setTimeout('ShowTime(\"' + ctrl +'\",true)',1000);
}
function checkTime(i)
{
  if (i<10) 
  {
    i="0" + i;
  }
  return i;
}
window.onload=function(){
ShowTime("jsClk");
};
</script>

"jsClk" is the id of a <label> tag which is located inside <body> tag.

1 Responses to "How to make a clock using javascript"

  1. ICZSCW <a href="http://eevtualhdakw.com/">eevtualhdakw</a>, [url=http://akiozjnkefva.com/]akiozjnkefva[/url], [link=http://idlylzdczxfj.com/]idlylzdczxfj[/link], http://ruejnnnhydil.com/

Leave a Reply