How to show current time in JavaScript in the format hh:mm:ss

  • Tech Area
  • April 24, 2023


I am working on a project where I need to show current (live) time on it. How do I implement current time in the format hh:mm:ss on my project using javascript.

Solution

<center><div id="time"></div></center>

<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>

<script>
     $(document).ready(function(){
          var interval = setInterval(function(){
               var momentNow = moment();
               $('#time').html(momentNow.format('hh:mm:ss A'));
          },100);
     });
</script>

Output


Subscribe us via Email

Join 10,000+ subscriber

Subscribe on YouTube