471,338 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

displaying the time

Hi Gurus

Is it possible to display the time on a site using javascript. I want to
show visitors the current time in New Zealand, but the javascript that I use
actually displays the time on the users computer (i.e. completely useless).

Any ideas greatly appreciated

Thanks in advance

- Nicolaas
Jul 23 '05 #1
7 1482
On Tue, 5 Oct 2004 11:49:10 +1300, WindAndWaves <ac****@ngaru.com> wrote:
Is it possible to display the time on a site using javascript. I want
to show visitors the current time in New Zealand, but the javascript
that I use actually displays the time on the users computer (i.e.
completely useless).


You can get UTC (GMT) time using the various UTC Date methods and adjust
the result with the appropriate offset. However, that depends on the
accuracy of the user's computer, so it might be just as useless.

You could always link to
<URL:http://www.worldtimeserver.com/?locationid=NZ>. I don't know exactly
how accurate they are.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsfd0f5iix13kvk@atlantis...
On Tue, 5 Oct 2004 11:49:10 +1300, WindAndWaves <ac****@ngaru.com> wrote:
Is it possible to display the time on a site using javascript. I want
to show visitors the current time in New Zealand, but the javascript
that I use actually displays the time on the users computer (i.e.
completely useless).


You can get UTC (GMT) time using the various UTC Date methods and adjust
the result with the appropriate offset. However, that depends on the
accuracy of the user's computer, so it might be just as useless.

You could always link to
<URL:http://www.worldtimeserver.com/?locationid=NZ>. I don't know exactly
how accurate they are.

Hi Mike

I think I am going to use that link and perhaps see if I can use PHP instead
of Java. That client-side really is not useful here. Thank you for that
link though, that is great. I actually downloaded the program that they
offer there to keep your clock up-to-date, as my clock does not seem to keep
up.

Thank you

Nicolaas
Jul 23 '05 #3
JRS: In article <mi*******************@news.xtra.co.nz>, dated Tue,
5 Oct 2004 11:49:10, seen in news:comp.lang.javascript, WindAndWaves
<ac****@ngaru.com> posted :

Is it possible to display the time on a site using javascript. I want to
show visitors the current time in New Zealand, but the javascript that I use
actually displays the time on the users computer (i.e. completely useless).


Read the newsgroup FAQ, posted here regularly and via sig line 2.
With care, that will lead you to <URL:http://www.merlyn.demon.co.uk/
js-date5.htm#Demo> ; select the fourth entry in the drop-down, then
Run. Check the TZ string.

Or enter Wellington NZST-12NZDT,M10.1.0/2:00,M3.3.0/2:00 as a
line in <URL:http://www.merlyn.demon.co.uk/js-date5.htm#SLHD>

Check the change dates & times.

RSVP any corrections.

The code can be simplified for a specific case, but then you are in
trouble if the NZ rules change.

If you're prepared to re-upload your page at the critical moment
each Spring and Autumn, of course, you only have to add 12 or 13
hours to GMT.

--
© 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

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:kB**************@merlyn.demon.co.uk...
JRS: In article <mi*******************@news.xtra.co.nz>, dated Tue,
5 Oct 2004 11:49:10, seen in news:comp.lang.javascript, WindAndWaves
<ac****@ngaru.com> posted :

Is it possible to display the time on a site using javascript. I want to
show visitors the current time in New Zealand, but the javascript that I useactually displays the time on the users computer (i.e. completely
useless).
Read the newsgroup FAQ, posted here regularly and via sig line 2.
With care, that will lead you to <URL:http://www.merlyn.demon.co.uk/
js-date5.htm#Demo> ; select the fourth entry in the drop-down, then
Run. Check the TZ string.

Or enter Wellington NZST-12NZDT,M10.1.0/2:00,M3.3.0/2:00 as a
line in <URL:http://www.merlyn.demon.co.uk/js-date5.htm#SLHD>

Check the change dates & times.

RSVP any corrections.

The code can be simplified for a specific case, but then you are in
trouble if the NZ rules change.

If you're prepared to re-upload your page at the critical moment
each Spring and Autumn, of course, you only have to add 12 or 13
hours to GMT.

--
© 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.

Dear John

I had a really good look at your page, but it looks rather technical! More
the kind of thing for a PhD..

Anyway, I am going to have a crack at it.

Thank you.
Jul 23 '05 #5
Is there a routine anywhere, not necessarily javascript, that can be
used to directly access a time server and display time, using
parameters to adjust for time zone, on a web site without going through
a third-party site?

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
Mail to the return email address is bounced.
Go to web site for active email address.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 23 '05 #6
JRS: In article <10*************************@dcsi.net>, dated Sun, 10
Oct 2004 09:05:03, seen in news:comp.lang.javascript, Dennis M. Marks
<de******@dcsi.net> posted :
Is there a routine anywhere, not necessarily javascript, that can be
used to directly access a time server and display time, using
parameters to adjust for time zone, on a web site without going through
a third-party site?


Yes, site www.heavens-above.com uses one, IIRC. Surely there are other
sites showing the capability.

It is sufficient to take code to access UTC/GMT from a server, and to
apply to its result the algorithms on my site, translated into language-
of-choice. The algorithms can be re-invented; and may be in the
libraries of some languages. Do not, however, trust any code written in
countries with a historical tradition of non-compliance with accepted
standards; if they can get it wrong, they will.

Allowing for time zone is trivial; one merely uses
setUTCHours(getUTCHours() + N) . Allowing for summer time transitions
given by reasonable rules is not too difficult. Allowing for the
decisions of politicians on time changes would require continuing
effort.

I don't know ASP, PHP, etc. - others here do - but ISTM that you could
use such technologies to deliver web-server time (which *should* be
time-server synchronised) with the page, which could determine the local
clock error, and then use my code, or similar, to display corrected
local time. Let the page self-refresh at intervals, to take out local
clock drift.

You don't say how the time zone required is to be determined; author's
choice, reader's choice, reader's location, ?.

One could use the time server to determine the current error of the
user's local GMT, which will (if the user is correctly configured) be
the same as the current error of the user's local local time (except
briefly at the summer/winter transitions), and can be used to correct
the latter for display.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #7
In article <MA**************@merlyn.demon.co.uk>, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote:
JRS: In article <10*************************@dcsi.net>, dated Sun, 10
Oct 2004 09:05:03, seen in news:comp.lang.javascript, Dennis M. Marks
<de******@dcsi.net> posted :
Is there a routine anywhere, not necessarily javascript, that can be
used to directly access a time server and display time, using
parameters to adjust for time zone, on a web site without going through
a third-party site?


Yes, site www.heavens-above.com uses one, IIRC. Surely there are other
sites showing the capability.


It seems as though the time is generated at the server since it is
already within the source of the page when I look at it. I should have
made it clear that I was looking for a non-server method. Maybe there
is somewhere in the site that the time is generated from code within a
page. If so, please point it out.

Is there a way to link to a time server, have data returned, and then
manipulate the returned data with code within a web page?

I do not have any current plans to use the code. I am just interested
in how and if it can be done at the user level.

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
Mail to the return email address is bounced.
Go to web site for active email address.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Lozzi | last post: by
11 posts views Thread by dba | last post: by
reply views Thread by rosydwin | last post: by

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.