title: How To Auto-Refresh the Time and Date Every Second (Live Time & Date)
body: <p>I have written a javascript code to fetch users' Dates and times and show it on the website but the problem is it's not auto-refreshing the data, every time you have to refresh the page to get the new update. I want to implement a system that auto updates the Date, Month, Year, Day &amp; Time (All) automatically even when the user stays on the page for a long time.</p>
  <p>My Format [04 March 2022, Friday - 03:18:33 PM]</p>
  <p>I would be very grateful for the help.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myDate = new Date();
  
  let daysList = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  let monthsList = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Aug', 'Oct', 'Nov', 'Dec'];
  
  
  let date = myDate.getDate();
  let month = monthsList[myDate.getMonth()];
  let year = myDate.getFullYear();
  let day = daysList[myDate.getDay()];
  
  let today = `${date} ${month} ${year}, ${day}`;
  
  let amOrPm;
  let twelveHours = function (){
      if(myDate.getHours() &gt; 12)
      {
          amOrPm = 'PM';
          let twentyFourHourTime = myDate.getHours();
          let conversion = twentyFourHourTime - 12;
          return `${conversion}`
  
      }else {
          amOrPm = 'AM';
          return `${myDate.getHours()}`}
  };
  let hours = twelveHours();
  let minutes = myDate.getMinutes();
  let seconds = myDate.getSeconds();
  
  let currentTime = `${hours}:${minutes}:${seconds} ${amOrPm}`; 
  
  document.write(today + ' ' + currentTime);  </code></pre>
  </div>
  </div>
  </p>