You are here: irt.org | FAQ | JavaScript | Date | Q586 [ previous next ]
Try this:
<form> <input name="timenow" type="text" size="8"> <input name="timethen" type="text" size="8"> </form> <script language="JavaScript"><!-- function padout(number) { return (number < 10) ? '0' + number : number; } function updateClocks() { now = new Date(); document.forms[0].timenow.value = padout(now.getHours()) + ':' + padout(now.getMinutes()) + ':' + padout(now.getSeconds()); now.setTime(now.getTime() - (1000*60*60*12)); document.forms[0].timethen.value = padout(now.getHours()) + ':' + padout(now.getMinutes()) + ':' + padout(now.getSeconds()); setTimeout('updateClocks()',500); } updateClocks(); //--></script>