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>

Comments

Popular posts from this blog

Solve

Solved practical slips of 12th Computer Science journal

SOLVE QUESTION ANSWERS ON OPERATING SYSTEM .