https://www.rakeshmgs.in/search/label/Template
https://www.rakeshmgs.in
RakeshMgs

Write a HTML JavaScript program to display the current day and time in the following format

Updated:

Write a HTML JavaScript program to display the current day and time in the following format

Sample Output:
Today is: Tuesday.
Current time is: 10 PM: 30:38

Note: Press Ctrl + C to copy after selection

<!DOCTYPE html>
<html>
  <head>
    <script>
      function displayDateTime() {
        var date = new Date();
        var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
        var day = days[date.getDay()];
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var seconds = date.getSeconds();
        var ampm = hours >= 12 ? "PM" : "AM";
        hours = hours % 12;
        hours = hours ? hours : 12;
        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;
        var currentTime = hours + " " + ampm + " : " + minutes + " : " + seconds;
        document.getElementById("day").innerHTML = "Today is: " + day + ".";
        document.getElementById("time").innerHTML = "Current time is: " + currentTime;
      }
    </script>
  </head>
  <body onload="displayDateTime();">
    <p id="day"></p>
    <p id="time"></p>
  </body>
</html>


Output




आपको आर्टिकल कैसा लगा? अपनी राय अवश्य दें
Please don't Add spam links,
if you want backlinks from my blog contact me on rakeshmgs.in@gmail.com