JavaScript Clock(Digital Clock)

Demo




Code

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function showTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
$("#clock").text(h+":"+m+":"+s);
t=setTimeout('showTime()',1000);
}
function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
</script>
<body onload="showTime()">
<div id="clock"></div>
</body>

This entry was posted in , , , . Bookmark the permalink.

7 Responses to JavaScript Clock(Digital Clock)

  1. i want the code where the timer starts from 00:00:00 when the user logged in to the system...pls..

    ReplyDelete
  2. Hi Please refer the below link

    http://www.knowlbase.in/p/counter.html

    ReplyDelete
    Replies
    1. Ya...this is exactly what i need...thank u very much...
      can i store its present value when a user logouts...?

      Delete
  3. helllo plss help i have a login time like 04:25:13 and a log out time like 04:26:29 and i want to find the login duration whose output will be like 00:01:16....anybody have the script for this...?

    ReplyDelete
  4. i want to remove seconds and show AM/PM ! please help

    ReplyDelete