473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to reliably get New York Time using Javascript

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
3 3100
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gernot Hillier | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi! I'm the developer of a Linux ISDN application which uses embedded Python for controlling the communication. It starts several threads (i.e....
4
by: DFS | last post by:
I have two nightly scheduled jobs at a client site - one at 2:00am and the other at 5:00am Both jobs launch Access 2003, log into the default system workgroup, open a Access .mdb that collects...
13
by: Jim Carlock | last post by:
I have over a hundred pictures I would like to present. Is it practical to create and parse an array of pictures, picture paths, et al using server-side scripting to accomplish this? I...
6
by: Arnie | last post by:
We're using the ServiceController class provided by the .NET Framework, programming in C#. We are using the Start() method to start a service from another service. This works fine most of the...
5
by: sfeher | last post by:
Hi, Is there a way to know when a function is available for me to call it from a dynamically loaded a javascript? I use this code to load the include.js file and then I call testIncludeFn()...
1
by: U S Contractors Offering Service A Non-profit | last post by:
Craig Somerford to New, Harvard, (bcc:Natural) More options 7:56 pm (0 minutes ago) " Working in Faith " " SNOWING over New York City Today November 7th 2006 "
0
by: dusty | last post by:
Please can anyone help me to get the time zone between GMT & New York including the daylight saving. I am able to get the timezone between GMT & localtime including the daylight saving. My program...
1
by: robert.oschler | last post by:
What's a good way to send tracking information to my server when a FORM submission occurs? Right now I build a URL that goes to a server side script that records the information. Then I set an IMG...
0
by: Ken North | last post by:
If you submit the best question for the workshop at LinkedData Planet, you'll win admission to the conference, including keynotes by W3C Director Sir Tim Berners-Lee, IBM CTO for Information...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.