JavaScript implements simple clock instance code

  • 2020-03-29 23:57:47
  • OfStack


<html>
<head>
<title>JS Implement a simple clock </title>
<script>
    function displayTime() {
        document.getElementById("time").innerHTML = new Date().toTimeString();
    } 

    setInterval(displayTime,1000);      //The displayTime function is called every 1 second
</script>
</head>
<body>
    <p id="time"></p>
</body>
</html>


Related articles: