Page 2 of 3

Re: Live Clock on a website?

Posted: Mon 20 Feb 2012 9:21 pm
by Rainfallman
Have a look at the world time server at http://www.worldtimeserver.com/ you can place a clock on a web page for any time zone. It may solve your problem.
rainfallman

Re: Live Clock on a website?

Posted: Sun 25 Mar 2012 6:48 am
by duke
Can some one tell me how to reconfigure this script to adjust BST on last sunday in march and last sunday in october?

From the authors website the script currently adjusts for:
To get the clock adjusting for daylight savings time between the first Sunday in October and the first Sunday in April (which is when it applies here) I added:
The script:

Code: Select all

// code to adjust for daylight saving time
 var gmt = new Date;var lsm = new Date;var lso = new Date;
 lsm.setMonth(3);lsm.setDate(7);
 var day = lsm.getDay();lsm.setDate(7-day);
 lso.setMonth(9);lso.setDate(7);
 day = lso.getDay();lso.setDate(7-day);
 if (gmt < lsm || gmt >= lso) dst = 1; 
Link to the site:Analogue Clock

Duke

Re: Live Clock on a website?

Posted: Sun 25 Mar 2012 12:35 pm
by beteljuice
Try:

Code: Select all

// code to adjust for daylight saving time
var gmt = new Date;var lsm = new Date;var lso = new Date;
lsm.setMonth(2);lsm.setDate(31);
var day = lsm.getDay();lsm.setDate(31-day);
lso.setMonth(9);lso.setDate(31);
day = lso.getDay();lso.setDate(31-day);
if (gmt > lsm && gmt < lso) dst = 1; 
... be warned the beteljuice always has problems with dates no matter what the code :roll:

Edit: debug alert line removed
Edit#2: Last line corrected :oops:

Re: Live Clock on a website?

Posted: Sun 25 Mar 2012 7:35 pm
by duke
beteljuice wrote: ... be warned the beteljuice always has problems with dates no matter what the code :roll:
Unfortunately it did not work :(

I don't understand js at all at the moment so I don't know where to start. Thanks for trying.

I've set the clock on my site manually at the moment but I really would like to solve this if some one knows how.

Thanks.

Duke

Re: Live Clock on a website?

Posted: Sun 25 Mar 2012 9:19 pm
by duke
I finally found what I was after :D . I guess this code (or something similar) would work for any js clock so I'll post it here.

To me it looks the same as beteljuice code so I don't understand why that did not work. May be op error ;) .
Here (in Sydney) we usually go onto daylight savings time at 2am on the last Sunday in October and back to standard time at 3am on the last Sunday in March. The following code will perform this switch at midnight visitor local time on those dates which is within a day of the correct time for the change. (To be more accurate than this would require about three times as much code which I don't think is worth it in this instance).

Code: Select all

var gmt = new Date;
 var lsm = new Date;
 var lso = new Date;
 lsm.setMonth(2); // March
 lsm.setDate(31);
 var day = lsm.getDay();// day of week of 31st
 lsm.setDate(31-day); // last Sunday
 lso.setMonth(9); // October
 lso.setDate(31);
 day = lso.getDay();
 lso.setDate(31-day);
 if (gmt < lsm || gmt >= lso) dst = 1; 
You would of course need to change the code to determine the appropriate dates for your local circumstances. Note that the month numbers run 0 = January through 11 = December and not 1 through 12.
Hope the code or explanation helps some one.

Duke

Re: Live Clock on a website?

Posted: Mon 26 Mar 2012 1:31 am
by beteljuice
I left a debug 'alert' in the code sorry.

Yes that's the same thing except I reversed the operands for the dst decision.
In my code dst = 1 at the moment because dst is in the 'Summer' for UK, whereas that (Australian) code dst is in UK 'Winter' - so that code should be backwards for the UK showing GMT hours ???

Re: Live Clock on a website?

Posted: Mon 26 Mar 2012 8:30 am
by duke
Thanks beteljuice. As suspected, op error crept in last night :oops: . When I cut and paste your code I pasted over "var dst = 0;" and that stopped the code working. Back in now and your code works a treat.

Therefore,
... be warned the beteljuice always has problems with dates no matter what the code
not true :D .

Cheers.

Duke

Re: Live Clock on a website?

Posted: Mon 26 Mar 2012 12:16 pm
by beteljuice
duke wrote: Therefore,
... be warned the beteljuice always has problems with dates no matter what the code
not true :D .
VERY true :oops:

I didn't finish reversing the logic !

Code: Select all

// if (gmt > lsm || gmt < lso) dst = 1; 
// should be

if (gmt > lsm && gmt < lso) dst = 1; 
but if you are feeling brave you could try:

Code: Select all

// code to adjust for daylight saving time
// mod by beteljuice to get last Sunday of month(s)
var gmt = new Date;var lsm = new Date;var lso = new Date; var dst=0;
lsm.setMonth(2);lsm.setDate(31); // 'Summer' start 2 = March which has 31 days
var day = lsm.getDay();lsm.setDate(31-day); // find the date of last Sunday in month
lsm.setUTCHours(0, 59, 59, 0); // clocks change 01:00 hrs UTC
lso.setMonth(9);lso.setDate(31); // 'Winter' start 9 = October which has 31 days
day = lso.getDay();lso.setDate(31-day); // find the date of last Sunday in month
lso.setUTCHours(0, 59, 59, 0); // clocks change 01:00 hrs UTC
if (gmt > lsm && gmt < lso) dst = 1; 

Re: Live Clock on a website?

Posted: Mon 26 Mar 2012 12:47 pm
by duke
beteljuice wrote: but if you are feeling brave you could try:

Code: Select all

// code to adjust for daylight saving time
// mod by beteljuice to get last Sunday of month(s)
var gmt = new Date;var lsm = new Date;var lso = new Date; var dst=0;
lsm.setMonth(2);lsm.setDate(31); // 'Summer' start 2 = March which has 31 days
var day = lsm.getDay();lsm.setDate(31-day); // find the date of last Sunday in month
lsm.setUTCHours(0, 59, 59, 0); // clocks change 01:00 hrs UTC
lso.setMonth(9);lso.setDate(31); // 'Winter' start 9 = October which has 31 days
day = lso.getDay();lso.setDate(31-day); // find the date of last Sunday in month
lso.setUTCHours(0, 59, 59, 0); // clocks change 01:00 hrs UTC
if (gmt > lsm && gmt < lso) dst = 1; 
Bravery in hand ;) . Copy - paste - FTP. Wait for page to load. Correct time displayed on site and local host. :clap:

Thanks for your time.

Duke

Re: Live Clock on a website?

Posted: Sat 05 May 2012 1:48 pm
by RayProudfoot
I've added the code for an analogue clock on my website. Could someone outside GMT+1 please check it shows UK time and not your own time zone please?
http://www.cheadlehulmeweather.co.uk/index.htm

Thanks.

Re: Live Clock on a website?

Posted: Sat 05 May 2012 2:02 pm
by tobyspond
Hi Ray,

Your clock appears to be showing the correct time. My local time is 10 am (eastern US) and your clock displayed 3 pm.

Kerry

Re: Live Clock on a website?

Posted: Sat 05 May 2012 2:14 pm
by RayProudfoot
Brilliant. Thanks Kerry.

Re: Live Clock on a website?

Posted: Sun 06 May 2012 3:41 am
by gemini06720
Ray, it is not showing the correct time in my browser - it is 20:40 here (local pacific daylight saving time) and the clock on the web page is displaying 04:40 AM... :(

You might want to have a look at the small JavaScript utility Duke is using on his web pages. ;)

Oh, did I forget to mention that I really dislike (to put it nicely) those gadgets with mouse-hover messages and links... :twisted:

Re: Live Clock on a website?

Posted: Sun 06 May 2012 3:52 am
by beteljuice
Could someone outside GMT+1 please check it shows UK time and not your own time zone please?

Re: Live Clock on a website?

Posted: Sun 06 May 2012 4:26 am
by PaulMy
At 12:15 a.m. here it seems to be showing your 5:15 time correctly.
Paul