Thursday, 10 April 2014

MAKE A SIMPLE CLOCK WITH JAVASCRIPT

                                                   

CODE=>

<html>
<head>
</head>
<body>
<script type="text/javascript">
function printtime()
{
var now=new Date();   
var hours=now.getHours();
var mins=now.getMinutes();
var seconds=now.getSeconds();
document.write(hours+":"+mins+":"+seconds+"<br>");
}
setInterval("printtime()",1000);
</script>
</html>

HOW IT WORKS=>
1.We made a function printtime() having variables now,hours,mins and seconds.
2.Variable now will get the current date.
3.The variables hours,mins,seconds will get the hour,minutes and seconds of the current date.
4.setInterval will call the function printtime repeatedly after every one second.

OUTPUT=>





No comments:

Post a Comment