Home Revolution Fullwidth Forums Tips & recommendations Digital Clock using JavaScript in HTML Field

Viewing 0 reply threads
  • Author
    Posts
    • #10345
      Alex
      Guest
      <style style="text/css">
      .clock {
        font-size: 4em;
      }
      </style>
      <script>
      function clock() {// We create a new Date object and assign it to a variable called "time".
      var time = new Date(),
          
          // Access the "getHours" method on the Date object with the dot accessor.
          hours = time.getHours(),
          
          // Access the "getMinutes" method with the dot accessor.
          minutes = time.getMinutes(),
          
          
          seconds = time.getSeconds();
      
      document.querySelectorAll('.clock')[0].innerHTML = harold(hours) + ":" + harold(minutes) + ":" + harold(seconds);
        
        function harold(standIn) {
          if (standIn < 10) {
            standIn = '0' + standIn
          }
          return standIn;
        }
      }
      setInterval(clock, 1000);
      </script>
      <div class="clock"></div>
Viewing 0 reply threads
  • You must be logged in to reply to this topic.