Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22220
| From | Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: OT: Displaying current time on a website |
| Date | 2013-11-30 20:35 +0000 |
| Organization | Home |
| Message-ID | <m+XP03t2vkmSFwlb@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | <l70gbn$b7j$1@dont-email.me> <l75ncg$qc2$1@dont-email.me> <l78evn$7jc$1@news.albasani.net> <l78jc8$o49$2@softins.softins.co.uk> <l7a3rn$7d6$1@softins.softins.co.uk> |
In comp.lang.javascript message <l7a3rn$7d6$1@softins.softins.co.uk>,
Fri, 29 Nov 2013 13:12:23, Tony Mountifield <tony@mountifield.org>
posted:
>function update() {
> var clock = document.getElementById('clock');
> var clienttime = new Date().getTime();
> var servertime = serverstart + (clienttime-clientstart);
> //
> clock.innerHTML = new Date(servertime).outputDate();
> setTimeout(update,1000-(servertime%1000));
>}
I think you do not need to ask to create a second Date Object. OTOH,
the system could easily choose not to create the first one.
function update() {
var clock = document.getElementById('clock'); //// A
var clienttime = new Date().getTime();
var servertime = serverstart + (clienttime-clientstart);
clienttime.setTime(servertime) //// B
clock.innerHTML = clienttime.outputDate(); //// C
setTimeout(update, 1000-(servertime%1000));
}
A) Outside the function will save a little execution time
B) Added
C) Altered
Now rename clienttime to suit the new code.
UNTESTED.
--
(c) John Stockton, Surrey, UK. ¬@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: OT: Displaying current time on a website Rhino <no_offline_contact_please@example.com> - 2013-11-27 16:15 -0500
Re: OT: Displaying current time on a website Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-28 01:11 +0000
Re: OT: Displaying current time on a website "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-11-28 11:20 +0200
Re: OT: Displaying current time on a website Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-29 00:12 +0000
Re: OT: Displaying current time on a website Andrew Poulos <ap_prog@hotmail.com> - 2013-11-29 13:51 +1100
Re: OT: Displaying current time on a website Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-29 10:58 +0100
Re: OT: Displaying current time on a website Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-11-29 21:30 +0000
Re: OT: Displaying current time on a website Stefan Weiss <krewecherl@gmail.com> - 2013-11-28 23:09 +0100
Re: OT: Displaying current time on a website tony@mountifield.org (Tony Mountifield) - 2013-11-28 23:24 +0000
Re: OT: Displaying current time on a website tony@mountifield.org (Tony Mountifield) - 2013-11-29 13:12 +0000
Re: OT: Displaying current time on a website Stefan Weiss <krewecherl@gmail.com> - 2013-11-29 14:39 +0100
Re: OT: Displaying current time on a website Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-11-30 20:35 +0000
Re: OT: Displaying current time on a website "Evertjan." <exjxw.hannivoort@interxnl.net> - 2013-12-01 07:57 +0000
csiph-web