You are here: irt.org | FAQ | DHTML | Q1414 [ previous next ]
The following is an adaptation of the script in the article The 24 Hour World, but without the daylight saving adjustment:
<html>
<head>
<script language="JavaScript"><!--
function padout(number) { return (number < 10) ? '0' + number : number; }
function ampm(time) {
var hours = time.getHours(), minutes = padout(time.getMinutes());
var adjhours = (hours == 0) ? 12 : ((hours < 13) ? hours : hours-12);
return ((adjhours < 10) ? ' ' : '') + adjhours + ':' + minutes + ':' + padout(time.getSeconds()) + ((hours < 12) ? ' am' : ' pm');
}
function updateTime() {
var time = new Date();
var TimezoneOffset = time.getTimezoneOffset();
var gmtX = 8; // Perth : GMT+8
time.setTime(time.getTime() - TimezoneOffset*60*1000 + gmtX*60*60*1000);
if (document.all)
document.all['clockTime'].innerText = 'Perth ' + ampm(time);
else if (document.layers) {
document.layers['clockTime'].document.open();
document.layers['clockTime'].document.write('Perth ' + ampm(time));
document.layers['clockTime'].document.close();
}
setTimeout("updateTime()",500);
}
//--></script>
</head>
<body onLoad="if (document.all || document.layers) updateTime()">
<span id="clockTime" style="position:absolute">
</span>
</body>
</html>