Connecting Tech Pros Worldwide Forums | Help | Site Map

Realtime clock that understands DST

Daz
Guest
 
Posts: n/a
#1: Jul 13 '07
Hi everyone.

I am trying to find out how I can create a real time clock, which
knows when to set itself backwards or forwards 1 hour. The clock will
work for various timezones. Some of which will not support DST.

If anyone has any suggestions as to how I might be able to achieve
this, I would very much appreciate it.


enrique
Guest
 
Posts: n/a
#2: Jul 13 '07

re: Realtime clock that understands DST


On Jul 13, 10:08 am, Daz <cutenfu...@gmail.comwrote:
Quote:
Hi everyone.
>
I am trying to find out how I can create a real time clock, which
knows when to set itself backwards or forwards 1 hour. The clock will
work for various timezones. Some of which will not support DST.
>
If anyone has any suggestions as to how I might be able to achieve
this, I would very much appreciate it.
If you're lucky, perhaps there is a time server on the 'net that
provides its services with an http interface.

Daz
Guest
 
Posts: n/a
#3: Jul 13 '07

re: Realtime clock that understands DST


On Jul 13, 3:12 pm, enrique <enrique.pin...@gmail.comwrote:
Quote:
On Jul 13, 10:08 am, Daz <cutenfu...@gmail.comwrote:
>
Quote:
Hi everyone.
>
Quote:
I am trying to find out how I can create a real time clock, which
knows when to set itself backwards or forwards 1 hour. The clock will
work for various timezones. Some of which will not support DST.
>
Quote:
If anyone has any suggestions as to how I might be able to achieve
this, I would very much appreciate it.
>
If you're lucky, perhaps there is a time server on the 'net that
provides its services with an http interface.
I was kind of hoping that, although I don't think I'd be able to
connect through Ajax due to cross-domain restrictions. I guess what I
should do really, is create one, that hands back a JavaScript time
object for the specified time zone.

I think the question I am really asking, is how can I find out when
the clocks go back or forwards next, automatically. I'm currently
trying to figure out how I can do this easily with PHP. I'm convinced
there is an easy way, that doesn't involved honing in on it with a
loop.

Evertjan.
Guest
 
Posts: n/a
#4: Jul 13 '07

re: Realtime clock that understands DST


enrique wrote on 13 jul 2007 in comp.lang.javascript:
Quote:
On Jul 13, 10:08 am, Daz <cutenfu...@gmail.comwrote:
Quote:
>Hi everyone.
>>
>I am trying to find out how I can create a real time clock, which
>knows when to set itself backwards or forwards 1 hour. The clock will
>work for various timezones. Some of which will not support DST.
>>
>If anyone has any suggestions as to how I might be able to achieve
>this, I would very much appreciate it.
>
If you're lucky, perhaps there is a time server on the 'net that
provides its services with an http interface.
On the other hand, it can easily be done using javascript.
I would say to the OP:

Start [learning javascript and] start building.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Daz
Guest
 
Posts: n/a
#5: Jul 13 '07

re: Realtime clock that understands DST


On Jul 13, 3:30 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Quote:
enrique wrote on 13 jul 2007 in comp.lang.javascript:
>
Quote:
On Jul 13, 10:08 am, Daz <cutenfu...@gmail.comwrote:
Quote:
Hi everyone.
>
Quote:
Quote:
I am trying to find out how I can create a real time clock, which
knows when to set itself backwards or forwards 1 hour. The clock will
work for various timezones. Some of which will not support DST.
>
Quote:
Quote:
If anyone has any suggestions as to how I might be able to achieve
this, I would very much appreciate it.
>
Quote:
If you're lucky, perhaps there is a time server on the 'net that
provides its services with an http interface.
>
On the other hand, it can easily be done using javascript.
I would say to the OP:
>
Start [learning javascript and] start building.
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
But "how"? lol

I've been working JavaScript for about a year now, but time zones are
unfamiliar territory. JavaScript doesn't really have the time zone
support I'd hoped for, so we have to work with offsets. Working with
offsets is not a problem. Knowing when to set a clock forwards or
backwards for time zone other than the one the client machine is at,
is not so easy. To my knowledge, this is impossible without some kind
of JavaScript NTP server. If you believe it is possible, I would very
much like to know how this can be done.

Evertjan.
Guest
 
Posts: n/a
#6: Jul 13 '07

re: Realtime clock that understands DST


Daz wrote on 13 jul 2007 in comp.lang.javascript:
Quote:
On Jul 13, 3:30 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Quote:
>enrique wrote on 13 jul 2007 in comp.lang.javascript:
>>
Quote:
On Jul 13, 10:08 am, Daz <cutenfu...@gmail.comwrote:
>Hi everyone.
>>
Quote:
>I am trying to find out how I can create a real time clock, which
>knows when to set itself backwards or forwards 1 hour. The clock
>will work for various timezones. Some of which will not support
>DST.
>>
Quote:
>If anyone has any suggestions as to how I might be able to achieve
>this, I would very much appreciate it.
>>
Quote:
If you're lucky, perhaps there is a time server on the 'net that
provides its services with an http interface.
>>
>On the other hand, it can easily be done using javascript.
>I would say to the OP:
>>
>Start [learning javascript and] start building.
>
But "how"? lol
>
I've been working JavaScript for about a year now, but time zones are
unfamiliar territory. JavaScript doesn't really have the time zone
support I'd hoped for, so we have to work with offsets. Working with
offsets is not a problem. Knowing when to set a clock forwards or
backwards for time zone other than the one the client machine is at,
is not so easy. To my knowledge, this is impossible without some kind
of JavaScript NTP server. If you believe it is possible, I would very
much like to know how this can be done.

Knowing the UTC methods of JS:

getTimezoneOffset()
getUTCDate()
getUTCDay()
getUTCFullYear()
getUTCHours()
getUTCMilliseconds()
getUTCMinutes()
getUTCMonth()
getUTCSeconds()
setUTCDate()
setUTCFullYear()
setUTCHours()
setUTCMilliseconds()
setUTCMinutes()
setUTCMonth()
setUTCSeconds()
UTC()

is always a great way to start.

The internal MS-Windows regional settings datafile for other timezones
is not available to clientside js, so you would have to build your own
data concerning the beginning and the end of summertime [in us-slang:
DST]

Adding an hour to time works like this:

d = new Date();

var diffHours = 1;

newTime = d.getTime() + diffHours * 60000);


Some of the John Stockton's Date/Time files seem not online,
but these are:

http://www.merlyn.demon.co.uk/js-dates.htm
http://www.merlyn.demon.co.uk/uksumtim.htm
http://www.merlyn.demon.co.uk/misctime.htm



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Daz
Guest
 
Posts: n/a
#7: Jul 13 '07

re: Realtime clock that understands DST


On Jul 13, 4:34 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Quote:
Daz wrote on 13 jul 2007 in comp.lang.javascript:
>
>
>
Quote:
On Jul 13, 3:30 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Quote:
enrique wrote on 13 jul 2007 in comp.lang.javascript:
>
Quote:
Quote:
On Jul 13, 10:08 am, Daz <cutenfu...@gmail.comwrote:
Hi everyone.
>
Quote:
Quote:
I am trying to find out how I can create a real time clock, which
knows when to set itself backwards or forwards 1 hour. The clock
will work for various timezones. Some of which will not support
DST.
>
Quote:
Quote:
If anyone has any suggestions as to how I might be able to achieve
this, I would very much appreciate it.
>
Quote:
Quote:
If you're lucky, perhaps there is a time server on the 'net that
provides its services with an http interface.
>
Quote:
Quote:
On the other hand, it can easily be done using javascript.
I would say to the OP:
>
Quote:
Quote:
Start [learning javascript and] start building.
>
Quote:
But "how"? lol
>
Quote:
I've been working JavaScript for about a year now, but time zones are
unfamiliar territory. JavaScript doesn't really have the time zone
support I'd hoped for, so we have to work with offsets. Working with
offsets is not a problem. Knowing when to set a clock forwards or
backwards for time zone other than the one the client machine is at,
is not so easy. To my knowledge, this is impossible without some kind
of JavaScript NTP server. If you believe it is possible, I would very
much like to know how this can be done.
>
Knowing the UTC methods of JS:
>
getTimezoneOffset()
getUTCDate()
getUTCDay()
getUTCFullYear()
getUTCHours()
getUTCMilliseconds()
getUTCMinutes()
getUTCMonth()
getUTCSeconds()
setUTCDate()
setUTCFullYear()
setUTCHours()
setUTCMilliseconds()
setUTCMinutes()
setUTCMonth()
setUTCSeconds()
UTC()
>
is always a great way to start.
>
The internal MS-Windows regional settings datafile for other timezones
is not available to clientside js, so you would have to build your own
data concerning the beginning and the end of summertime [in us-slang:
DST]
>
Adding an hour to time works like this:
>
d = new Date();
>
var diffHours = 1;
>
newTime = d.getTime() + diffHours * 60000);
>
Some of the John Stockton's Date/Time files seem not online,
but these are:
>
http://www.merlyn.demon.co.uk/js-dat...k/misctime.htm
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
I was aware of the UTC function within JavaScript, I was just unsure
about how to know when to set the clocks backwards or forwards.

Thanks for the URLs, they are very helpful. I think I am going to look
into a PHP solution which others can use, which will send a JavaScript
object/array containing information about a particular time zone, such
as if DST is currently used, when the clock goes back/forward next,
and when.

Thanks again.

Evertjan.
Guest
 
Posts: n/a
#8: Jul 13 '07

re: Realtime clock that understands DST


Daz wrote on 13 jul 2007 in comp.lang.javascript:
Quote:
Thanks for the URLs, they are very helpful. I think I am going to look
into a PHP solution which others can use, which will send a JavaScript
object/array containing information about a particular time zone, such
as if DST is currently used, when the clock goes back/forward next,
and when.
>
On the serverside, using asp:

I have websites for the Netherlands on servers in Toronto,
so I use this conversion include,
using serverside j[ava]script to determine the timeoffset,
and vbscript for the rest.

I do no need any knowledge about Canadian DST switch data/times,
and Central European Time quirks are wellknown over here.

Now is Toronto local time.
nuGMT is UTC.
nu is Central European local time.
nudag is the local time string.

===========================================
<% ' vbscript
nuGMT = DateAdd("h", TimezoneOffset, Now)
nu = DateAdd("h", 1, nuGMT)
If nuGMT>#2007-03-25 01:00# then nu = DateAdd("h", 2, nuGMT)
If nuGMT>#2007-10-28 01:00# then nu = DateAdd("h", 1, nuGMT)
If nuGMT>#2008-03-30 01:00# then nu = DateAdd("h", 2, nuGMT)
If nuGMT>#2008-10-26 01:00# then nu = DateAdd("h", 1, nuGMT)

nudag = day(nu) & "/" & month(nu) & " " & right("0"&hour(nu),2) & ":" &
right("0"&minute(nu),2) & ":" & right("0"&second(nu),2)
%>

<script language='jscript' runat='server'>
var TimezoneOffset = new Date().getTimezoneOffset()/60;
</script>
===========================================

John Stockton wrote a computed European switch rule code here:

http://groups.google.com/group/comp.lang.javascript/msg/858cf852a991445c>

In js-date5.htm (M=3 or M=10) :

function EUch(Y, M) { // return ms of Spring/Autumn EU clock change
var J = Date.UTC(Y, M-1, 31) // last of month is 31st, get UTC
return J - 864e5*((4+J/864e5)%7) + 36e5 /* Sun, 0100 GMT, ms */
}

[Not tested now]



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Closed Thread


Similar JavaScript / Ajax / DHTML bytes