Home > Javascript > Display Time with Javascript

Display Time with Javascript


Hi

try this example to display time in format (hh:mm:ss) format using Javascript

<script language="JavaScript">
function tick() {
  var hours, minutes, seconds, ap;
  var intHours, intMinutes, intSeconds;
  var today;
  today = new Date();
  intHours = today.getHours();
  intMinutes = today.getMinutes();
  intSeconds = today.getSeconds();

  if (intHours == 0) {
     hours = "12:";
     ap = "AM";
  } else if (intHours < 12) {
     hours = intHours+":";
     ap = "AM";
  } else if (intHours == 12) {
     hours = "12:";
     ap = "PM";
  } else {
     intHours = intHours - 12
     hours = intHours + ":";
     ap = "PM";
  }

  if (intMinutes < 10) {
     minutes = "0"+intMinutes+":";
  } else {
     minutes = intMinutes+":";
  }

  if (intSeconds < 10) {
     seconds = "0"+intSeconds+" ";
  } else {
     seconds = intSeconds+" ";
  }

  timeString = hours+minutes+seconds+ap;
  Clock.innerHTML = timeString;
  window.setTimeout("tick();", 1000);
}

window.onload = tick;

</script>

<div id="Clock" style="display: inline; font-size: 13pt;width: 100%; height: 19px; text-align: center">
      <strong><font color="#009900"></font></strong>
    </div>

Hope this helps

Good Luck

Advertisements
Categories: Javascript Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: