Jump to content

Making two clocks


Strygun

Recommended Posts

Hey folks,

 

I've found some code on the internet that will create a very simple (which is what I need) javascript clock that displays the current user's time. However, I would like to create a second clock to go right with it that will display the current time in London (GMT-0).

 

Here's the code I currently have:

<script type="text/javascript">
function createtime()
{
var time = new Date()
var hours = time.getHours()
var minutes = time.getMinutes()
var seconds = time.getSeconds()
var abbrev = "AM"
if (hours>=12)
abbrev="PM"
if (hours>12)
{
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
var ctime=""+hours+":"+minutes+":"+seconds+" "+abbrev+""
if (document.all)
document.all.clock.innerHTML=ctime
else if (document.getElementById)
document.getElementById("clock").innerHTML=ctime
else
document.write(ctime) }
if (!document.all&&!document.getElementById)
createtime()
function loadtime()
{
if (document.all||document.getElementById)
setInterval("createtime()",1000)
}
</script>
<body onLoad="loadtime()">
<center><font size="1.5">Your Time: <span id="clock"></span></font> 

 

This clock works perfectly for displaying the current time based upon the viewer's PC clock. I'm sure it can't be too difficult to add a clock that displays the  time in London.

If it can help, there is this clock that looks great and displays multiple timezones (surely by just adding or subtracting from the user's current clock. whatever needs to be done..) http://www.arachnoid.com/lutusp/worldclock.html the source is also available there as well.

 

Thanks folks,

Link to comment
https://forums.phpfreaks.com/topic/66066-making-two-clocks/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.