JavaScript Example: Print Current Time

This JavaScript example prints the current time.

Click me to show time.

function gettime() {
  var dd = new Date();
  var hh = dd.getHours();
  var mm = dd.getMinutes();
  var ss = dd.getSeconds();
  alert("The time is now: " + hh + ":" + mm + ":" + ss);
}
<p onClick="gettime(); return false;">Click me to show time.</p>
2005-06
© 2005 by Xah Lee.