Time and Date Displayed In Form

[Total: 0    Average: 0/5]

This shows how to have a form text box display the current time down to the second.

Body Code:

<form name=exf1>
  <INPUT TYPE=text NAME=time size=30 value='<clock not started>'>
</form> 
<script type=text/javascript>
function showtime () {
  var today = new Date(); // this returns the current time [object]
  var year    = today.getYear();
  var month   = today.getMonth() + 1; // value returned is from 0 to 11
  var date    = today.getDate();
  var hours   = today.getHours();
  var minutes = today.getMinutes();
  var seconds = today.getSeconds();
  var day     = today.getDay();
  Day = new Array("SUN","MON","TUE","WED","THU","FRI","SAT");
  var _t  = "";
      _t += Day[day]+" ";
      _t += month+"/"+date+"/"+year+" ";
      _t += hours%12;
      _t += minutes<10?":0":":";
	  _t += minutes;
      _t += seconds<10?":0":":";
	  _t += seconds;
      _t += hours<12?" AM":" PM";
  document.exf1.time.value = _t;
}

function startIt() { setInterval("showtime()",1000) }
</script> 
<BR><a href="javascript:startIt()">Start Clock</a>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *