<html>
<head></head>
<title></title>
<body>
<p id="printClock></p>
<button onclick= "clearInterval(clock )">Stop Time</button> <!--to stop time ---->
<button onclick= " setInterval(clocktiming, 1000)">Restart Time</button><!---to restart the time-->
<script>
var clock = setInterval(clocktiming, 1000); // setInterval(function,time in millsecond)
function clocktiming( )
{
var d = new.date(); // contains all date,time
var t = d.toLocaleTimeString(); //Extract time only from d object
document.getElementById('printClock').innerHTML = t ;
}
</script>
</body>
</html>
Note: setInterval( ) calls the function at specified time in millisecond.
Just once it stop and restart the time.
No comments:
Post a Comment