Window setInterval() Method - Display the current time every 1 second, just like a digital watch - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setInterval

Description

Window setInterval() Method - Display the current time every 1 second, just like a digital watch

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var myVar = setInterval(function(){ myTimer() }, 1000);

function myTimer() {/*  w ww. ja va2s. c o m*/
    var d = new Date();
    var t = d.toLocaleTimeString();
    document.getElementById("demo").innerHTML = t;
}
</script>

</body>
</html>

Related Tutorials