Javascript clock

I’ve added a javascript clock… actually, bristolwx’s website gave me the idea.

However, I think I’ve improved on it by having it always show MY time based on the time on YOUR computer.

Can I get a few people to check and see if it is showing the correct time?

Mine is -5 UTC (CDT) and you can also compare to the time at the bottom of the page that says:

Carter Lake Update: X:XXX XM X/X/2004

Here’s the original clock code:
http://javascript.internet.com/clocks/basic-clock.html

And the modified code

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Modified by Tom Chaplin to make this a local time clock -->

<!-- Begin
function clock() {
var digital = new Date();
var hours = digital.getUTCHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
var offset = 6 ; <!-- Offset value is 5 for CDT and 6 for CST -->

if (hours < offset)
      {hours = hours + 24 - offset; } <!-- If hours < 0 add 24 for correct time -->
      else
      {hours = hours - offset; }  <!-- Else just subtract it. -->

var amOrPm = "AM";
if (hours > 11) amOrPm = "PM";
if (hours > 12) hours = hours - 12;
if (hours == 0) hours = 12;
if (minutes <= 9) minutes = "0" + minutes;
if (seconds <= 9) seconds = "0" + seconds;
dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
document.getElementById('pendule').innerHTML = dispTime;
setTimeout("clock()", 1000);
}
//  End -->
</script>

You mean the time displayed under the “feels like”?

You mean the time displayed under the "feels like"?

Sorry… yes… the clock under “feels like” that’s ticking off the seconds.

The time displayed is consistent with the update time, so I guess that means it’s working for me :slight_smile:

The time displayed is consistent with the update time, so I guess that means it's working for me :)

Great! Thanks.

Can you see the streaming video? (click on small picture of nice bright day)

Yes, I see that, at least the seconds are incrementing, but it looks a pretty calm day.

Aha, it really does work, I just saw someone drive past the mailbox :rofl:

Cool. Everything seems to be working (and working together).

If it’s supposed to be showing your time then it’s correct - same as update - 6 hours behind me in the UK.

The live video just says ‘Loading Java Applet Failed…’ in status bar. Might be an SP2 thing.

Julian

hmm - problem now that it is after 1am here in the UK

time is being displayed as a negative value

-5:11:30 for example at the moment - so the hours-6 is being taken literally!

probably needs something like

if (hours <= 0) hours = hours + 12

added to the code??

If it's supposed to be showing your time then it's correct - same as update - 6 hours behind me in the UK.

The live video just says ‘Loading Java Applet Failed…’ in status bar. Might be an SP2 thing.

Julian

If the applet failed, it’s due to some security/firewall setting -OR- you have Sun’s JVM 1.4.2

hmm - problem now that it is after 1am here in the UK

time is being displayed as a negative value

-5:11:30 for example at the moment - so the hours-6 is being taken literally!

Ah… need to add an IF statement probably.

Just checked
8:17pm here (eastern US)

Your clock is showing -5:17 (negative)

Also, your live streaming video is showing a “red x” for me (I’m running Sun Java).

showing UTC time now - as I added above - will

if (hours <= 0) hours = hours + 12 (or 24 if before the hours - 12 bit?)

do the trick?

If it doesn’t work with Sun Java that’s going to be a problem, MS java is gone, it hasn’t been shipped with IE for several months now.

Time’s not good for me now, shows 12:30 AM should be 7:30 PM

2:34 PM now

Hey, that’s what I have too.

the line that is doing that is

if (hours - 5 >= 0) hours = hours - 5;

if that line is not there then you will have the correct time

Uh… had to remember the syntax…

You guys are catching me mid “fiddle with code”

Better?