PDA

View Full Version : displaying different text depending on time.


HELLSS
12-16-2002, 06:17 AM
I've looked through tons of javascripts but can't remember if i've come across one which does what I want now.

I want a script which will display a text message depending on the time of day on that persons computer (or any way of controlling the time).

So like at 5 a.m. it would display "good morning blah blah" until the next text display is triggered at say 11 a.m. saying "good afternoon blah blah" and so on... know of such a script?

Thanks for helping this javascript illiterate man :p

Skyzyx
12-16-2002, 06:36 AM
Would something like this help?


var now = new Date();
var timeOfDay = now.getHours();

// 10:00pm to 12:59am
if (timeOfDay == 0 || timeOfDay > 21) document.write("Isn't it bedtime soon?");

// 1:00am to 4:59am
else if (timeOfDay >0 && timeOfDay <5) document.write("You're up a bit late, aren't you?");

// 5:00am to 7:59am
else if (timeOfDay >4 && timeOfDay <8) document.write("A bit of an early bird, aren't ya?");

// 8:00am to 11:59am
else if (timeOfDay > 7 && timeOfDay < 12) document.write("Good Morning!");

// 12:00pm to 5:59pm
else if (timeOfDay > 11 && timeOfDay < 18) document.write("Good Afternoon!");

// 6:00pm to 9:59pm
else if (timeOfDay > 17 && timeOfDay < 22) document.write("Good Evening!");


Remember, the value of timeOfDay is only the hour, so 3:00 through 3:59 are still the 3 O'clock hour.

Also, remember that this works in 24-hour time, not 12-hour (am/pm) time.

Other than that, you should be set!

HELLSS
12-16-2002, 08:06 AM
tis perfect :thumbsup:

*bows*

thanks a lot.