Display the current time.
The setInterval()
method will execute the function once every 1 second:
<!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>