Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q586 How can I show clocks, one showing the current time, and another showing a time 12 hours behind?

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>

©2018 Martin Webb