Javascript Browser Window setInterval() Method display current time

Introduction

Display the current time.

The setInterval() method will execute the function once every 1 second:

View in separate window

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var myVar = setInterval(myTimer, 1000);

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

</body>
</html>



PreviousNext

Related