By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,501 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,501 IT Pros & Developers. It's quick & easy.

How to reliably get New York Time using Javascript

P: n/a
I'm coding up a small little script that's supposed to be used to
display the number of hours until the US Financial markets open/close.
Naturally, this involves getting the current time on the eastern
seaboard, which, upon reflection, seems a little more difficult than I'd
thought.

This is largely because of daylight savings time. It's easy to grab
UTC/GMT time using javascript and subtract 4/5 hours. The thing that
doesn't seem trivial is how to determine which -- how to determine if
(a) the script viewer is in a location which has daylight
savings/standard times and (b) if so, whether or not daylight savings is
in effect.

I can grab the local time as a string, and regexp against it for
"Daylight" -- however, since not all regions use this, it's clearly not
a reliable method.

Any ideas?

Thanks,

Weston

~==~
http://weston.canncentral.org/
Taking Pictures During Dreams
weston8[at]cann8central.org
(remove eights to email me)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Weston C wrote:
I'm coding up a small little script that's supposed to be used to
display the number of hours until the US Financial markets open/close.
Naturally, this involves getting the current time on the eastern
seaboard, which, upon reflection, seems a little more difficult than I'd
thought.

This is largely because of daylight savings time. It's easy to grab
UTC/GMT time using javascript and subtract 4/5 hours. The thing that
doesn't seem trivial is how to determine which -- how to determine if
(a) the script viewer is in a location which has daylight
savings/standard times and (b) if so, whether or not daylight savings is
in effect.

I can grab the local time as a string, and regexp against it for
"Daylight" -- however, since not all regions use this, it's clearly not
a reliable method.

Any ideas?

Thanks,

Weston

~==~
http://weston.canncentral.org/
Taking Pictures During Dreams
weston8[at]cann8central.org
(remove eights to email me)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Having just been through the exercise of figuring out US Times (
particularly the concept of "yesterday" when yesterday is actualy 2 days
ago ;-{ ) try timeserver.com and extract the actual NY time from there.
It accepts parameters in the URL ("
http://worldtimeserver.com/time.aspx?locationid=US-NY" ) will give the
current NY time.

Searching through the source is a PITA but it works ! Actually NY is -5
UTC at the moment.
Jul 23 '05 #2

P: n/a
Weston C wrote:
I'm coding up a small little script that's supposed to be used to
display the number of hours until the US Financial markets open/close.
Naturally, this involves getting the current time on the eastern
seaboard, which, upon reflection, seems a little more difficult than I'd
thought.

This is largely because of daylight savings time. It's easy to grab
UTC/GMT time using javascript and subtract 4/5 hours. The thing that
But you are relying on the user's machine being accurately and
correctly set, neither of which you can be certain of.
doesn't seem trivial is how to determine which -- how to determine if
(a) the script viewer is in a location which has daylight
savings/standard times and (b) if so, whether or not daylight savings is
in effect.
The users' timezone can be made irrelevant. Calculate the time
to market open where you are, then send it as a value in your
web page. Use setTimeout or similar to provide a countdown -
local times are now of no consequence.

You will be in error by the amount of time it takes to download
the file and for the page to start the count, however that can be
minimised and if you only report to the nearest minute (with an
appropriate disclaimer as to the accuracy of your timer) you
should be OK.

Put the script and offset at the very start of the page and it
should start counting a few seconds after you calc the value at
your server.

You also need to allow for local NY public holidays and other
non-trading days or half-days.
I can grab the local time as a string, and regexp against it for
"Daylight" -- however, since not all regions use this, it's clearly not
a reliable method.


No, it isn't. For further information, read:

<URL:http://www.merlyn.demon.co.uk/js-dates.htm>

--
Fred
Jul 23 '05 #3

P: n/a
JRS: In article <41**********@127.0.0.1>, dated Fri, 7 Jan 2005
20:15:23, seen in news:comp.lang.javascript, Weston C <west8on@[at]>
posted :
I'm coding up a small little script that's supposed to be used to
Are there other sizes of little script?
display the number of hours until the US Financial markets open/close.
Naturally, this involves getting the current time on the eastern
seaboard, which, upon reflection, seems a little more difficult than I'd
thought.
Read the newsgroup FAQ, carefully. It should lead you to Page 5, #NYT.
This is largely because of daylight savings time. It's easy to grab
UTC/GMT time using javascript and subtract 4/5 hours. The thing that
doesn't seem trivial is how to determine which -- how to determine if
(a) the script viewer is in a location which has daylight
savings/standard times
That is irrelevant. You only need to implement US clock rules, and hope
they do not get changed; or use a general parameterised method.
and (b) if so, whether or not daylight savings is
in effect.
That is pointless; what if the user is in Iraq, or Port Stanley, or
Brussels?

It's also easy enough; determine getTimezoneOffset() for Jan 1, current,
and Jul 1. If the nominal location has Summer Time, script can tell
whether it is North or South and whether it is Summer or Winter there;
it can always tell the nominal longitude of its time zone.
I can grab the local time as a string, and regexp against it for
"Daylight" -- however, since not all regions use this, it's clearly not
a reliable method.
The local time, as given by my browser, contains no words. The local
time is irrelevant for what you ask.

It is, presumably, the client user who is to benefit; you need not worry
whether his settings are correct, but you can tell him to do so.
Any ideas?


Read the newsgroup FAQ; see below.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.