JRS: In article <11************ **********@z14g 2000cwz.googleg roups.com>
, dated Mon, 13 Dec 2004 16:06:52, seen in news:comp.lang. javascript,
go****@ghosthou nds.com posted :
I have a website that hosts a java chat room nightly. I'd like to have
a graphic on the main page that toggles between 2 images - one
advertising the time of the chat, and another that appears during the
time the chat is actually in session inviting visitors to the web site
to join the chat.
Any idea how I might do this in Javascript to schedule the imgage
substitution using a general meridian time function?
Thanks for your suggestions!
T = new Date().getUTCHo urs()
src = ['a', 'b'][+(T>=20 && T<22)] + ".gif"
will compute the name of the image to load, changing at 20h & 22h UTC.
new Date()%864e5/36e5|0 // also gets UTC hour-of-day; note |
If you want a Web page to change dynamically when the user's machine
thinks the UTC is right,
new Date()%864e5 // UTC millisecond-of-day
can be used to compute the exact interval to the next status change, for
a setTimeout to load the new image and recompute the interval.
To be more exact, given the potential for user clock adjustment,
calculate the image letter index once a minute and see if it has
changed.
If the times are not whole hours, divide by 6e4 instead to get minute of
UTC day.
BTW, not that it affects you, ISTM that a server cannot initially know
the user's local time, but it may be able to get javascript to send it
the user's offset from GMT.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.