
Originally Posted by
gyancher
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
HTML Code:
<script type="text/javascript">
and remove the comment (the one at the end, too).
You could simply things a lot in this function by defining a few utility methods and using modulus, rather than arithmetic.
Code:
Number.prototype.pad = function(length, radix) {
return (+this).toString(+radix || 10).pad(length, '0');
};
String.prototype.pad = function(length, character) {
var s = String(this),
i = s.length;
while(i < length) {s = character + s;}
return s;
};
function updateTime() {
var now = new Date(),
elements = document.forms.clock.elements,
tail = ':' + now.getMinutes().pad(2)
+ ':' + now.getSeconds().pad(2);
elements.local.value = now.getHours().pad(2) + tail;
elements.ho.value = ((now.getUTCHours() + 8) % 24).pad(2) + tail;
elements.tky.value = ((now.getUTCHours() + 9) % 24).pad(2) + tail;
/* etc. */
}
Of course, that doesn't address the issue of time zones. Dr Stockton does, on the basis of the TZ database, which you can read in his section on general, remote civil date and time. If need be, I'll expand the code above to include the relevant algorithms, but I doubt I'll have time until tomorrow.
<BODY onLoad="javascript
:GetTime();">
The javascript: is unnecessary.
Mike
Bookmarks