Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1414 How can I show the time in Perth in a layer?

irt.org | Knowledge Base | DHTML | Q1414 [ previous next ]

Q1414 How can I show the time in Perth in a layer?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.