Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q468 How can I detect the hour of the day, and then when someone selects a link, they go to either a "day" page or a "night" page?

irt.org | Knowledge Base | JavaScript | Date | Q468 [ previous next ]

Q468 How can I detect the hour of the day, and then when someone selects a link, they go to either a "day" page or a "night" page?

Try this:

<SCRIPT LANGUAGE = 'JavaScript'><!--
var date = new Date();
var hours = date.getHours();
if ( (hours < 6) || (hours > 18) )
    document.write('<A HREF="night.html">click this link<\/A>');
else
    document.write(<A HREF="day.html">click this link<\/A>');
//--></SCRIPT>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.