Click to See Complete Forum and Search --> : Script For Clock Displaying Current Time in Specific Location
daryl
09-26-2003, 03:31 AM
can someone do me a BIG favor by helping me with this? I know nothing about javascipt, so I'll be needing all your help.
Thanks.
What I need is a running digital clock which displays the time for a specific location. To be more specific, Singapore.
What I'd want is a clock which displays Singapore's time regardless fo where the viewer is.
Thanks if you can help me!
lillu
09-26-2003, 03:59 AM
Here's a link where can check your zone here: http://www.csgnetwork.com/timecalc.html
Then you can check out the script here: http://www.csgnetwork.com/localtimezonecalc.html
Nice ticking digital clock:
http://www.csgnetwork.com/timezncvt.html
daryl
09-26-2003, 04:10 AM
Hm.
Sorry to sound stupid, but where on those sites can I find the script?:confused:
Gollum
09-26-2003, 04:24 AM
I don't think there is any specific support in the Javascript Date object for playing around with time zones, but in this case it should be quite easy to DIY.
Fortunately Singapore has no daylight savings time and so all you need to do is add 8 hours to GMT...
<html>
<head>
<script>
function formatTimeSegment(t)
{
return t < 10 ? ('0' + t) : t.toString();
}
function singaporeClock()
{
var gmt = new Date();
var sing = new Date(gmt.getTime() + 8 * 3600000);
var oDiv = document.getElementById('singaporeClockDiv');
oDiv.innerHTML =
formatTimeSegment(sing.getUTCHours()) + ':' +
formatTimeSegment(sing.getUTCMinutes()) + ':' +
formatTimeSegment(sing.getUTCSeconds());
window.setTimeout("singaporeClock();", 1000 - gmt.getMilliseconds());
}
</script>
</head>
<body onload="singaporeClock();">
<span id="singaporeClockDiv"></span>
</body>
</html>
daryl
09-26-2003, 04:29 AM
Ah...
Thank You SO MUCH!!!:)
lillu
09-26-2003, 07:02 AM
Hi daryl,
Go to toolbar, View - Source (in IE) to view html code of the page.
If a script is being executed on a page it is called from somewhere eg. a link or button a user can click on.
If you mouse over such a link, the status bar will give you the name of the function associated with that link/button etc, so you can look for that specific function in the code.
HTH
daryl
09-29-2003, 07:22 AM
Thanks A lot.
I've decided to use Gollum's script.
Now, I need another script to countdown, to say, seconds accuracy, with the same time format shown in the previous timer. I need it to work on the same page as the previous script, and also location specific. If you could, also a count up timer to same time.
I have nothing to give in return, but greates appreciation.
Thank You!
daryl
09-29-2003, 07:55 AM
Originally posted by daryl
Thanks A lot.
I've decided to use Gollum's script.
Now, I need another script to countdown, to say, seconds accuracy, with the same time format shown in the previous timer. I need it to work on the same page as the previous script, and also location specific. If you could, also a count up timer to same time.
I have nothing to give in return, but greates appreciation.
Thank You!
Not to the same time, for the count up, sorry! From another date, this one specific from year to seconds. To be even more specific, a count up from my time of birth. The countdown would be to my next birthday.
daryl
09-29-2003, 09:42 AM
anybody? i noe it's a lot to be asking for, but please?:(
daryl
09-29-2003, 09:37 PM
anyone? please?:(
You can do that with a few simple modifications to Gollum's script:
<script type="text/javascript">
function formatTimeSegment(t) {
return t < 10 ? ('0' + t) : t.toString();
}
var date = new Date();
var offset = 0; //set up the offset variable
function singaporeClock() {
gmt = new Date(date-offset); //set gmt to the date when the page was loaded, minus the offset
var sing = new Date(gmt.getTime() + 8 * 3600000);
var oDiv = document.getElementById('singaporeClockDiv');
oDiv.innerHTML =
formatTimeSegment(sing.getUTCHours()) + ':' +
formatTimeSegment(sing.getUTCMinutes()) + ':' +
formatTimeSegment(sing.getUTCSeconds());
offset = offset+1000; //increase the offset
window.setTimeout("singaporeClock();", 1000);
}
</script>Though if you want them to be running on the same page at the same time, you'll have to change the function and variable names to something unique.
daryl
09-29-2003, 10:08 PM
Thanks for your reply.
If I want to be counting down to 14 October 1751hr Singapore time, which parts should I change, and to what?
I also need it to display months and days.
Thanks a lot. You guys providing this wonderful free help service is just so wonderful!
Does anyone know how to show the server ticking clock in my page that is in IIS 4.
Thanks.