google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: JavaScript program to create a JavaScript object to show the current time

Tuesday, December 17, 2019

JavaScript program to create a JavaScript object to show the current time

<!DOCTYPE html>
<title>Current time</title>

<time id="time"></time>
<script language="javascript">
  /*Create a JavaScript object for the current time,then extract the desired parts, then join them again in the desired format.*/

  var currentTime = new Date(),
      hours = currentTime.getHours(),
      minutes = currentTime.getMinutes();
 
 
  if (minutes < 10) {
    minutes  = "0" + minutes;
  }

 
var suffix = "AM";
if (hours >= 12) {
    suffix = "PM";
    hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}


  time = hours + ":" + minutes + " " + suffix;
     
  // Output
  document.getElementById("time").innerHTML = time;
</script>

No comments:

Post a Comment

हिम्मत

 अंधेरे में एक करोड का हीरा गिर गया था, उसे ढूंढने के लिए पाँच रूपएं की मोमबत्ती ने सहयोग किया। अभी बताओ वह पाँच रूपएं की एक छोटी सी मोमबत्त...