Sunday, 16 March 2014

Display Current Time on Page using Javascript


Display Current Time on Page using Javascript


Use the following Code-Snippet to display Current Time using Javascript...


<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
</script>
<title>Display Current Time</title>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
</html> 

No comments:

Post a comment

Thank You for Your Comments. We will get back to you soon.

back to top