whatever_la
07-03-2003, 02:47 PM
Is there a script that shows different messages at different times?
1) Say I want it to say Good Morning in 6-7am of the user's computer's clock, but say Good Night at 6-7pm of the user's computer's clock & so on......
2) Can a similar script, with the only change that the time is not according to the user's computer's clock, but with a standard time, say Pacific Central Time
Thanks :)
whatever_la
07-03-2003, 02:57 PM
Hm... sorry for double posting, but I find the script from http://www.javascript-page.com/chclock.html :
<center>
<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com
day = new Date()
hr = day.getHours()
hr1 = hr - 12
if (hr < "6") {
document.write("Go back to bed!! "+hr+" AM is too early!")
}
else if (hr < "12") {
document.write("Good morning. It's "+hr+" AM.")
}
else if (hr < "13") {
document.write("Lunch time! It's "+hr+" M")
}
else if (hr < "17") {
document.write("Good Afternoon. It's "+hr1+" PM")
}
else if (hr < "22") {
document.write("Good Evening. It's "+hr1+" PM")
}
else if (hr > "21") {
document.write("Good night. It's "+hr1+" PM, Go to sleep.")
}
//-->
</script>
</center>
However, I'll still like to nkow how to edit this & add more welcome messages like Hi! It's Tea time, etc.
Thanks :)
burningstars
07-03-2003, 04:37 PM
All you have to do is edit each one that says something like this:
if (hr < "6") {
document.write("Go back to bed!! "+hr+" AM is too early!")
Just change the if (hr<"6") { to the hour you want like if you want it to be anytime before 6 am then you would leave it that way but if you want it to be earlier than that than just change the 6.
To change the message just change the document.write("Go back to bed!! "+hr+" AM is too early!") part to what you want it to say! The +hr+ just displays the hour that it is like if it is 6 AM the +hr+ will but the number 6 where it is!
If you have any other questions let me know! :)
whatever_la
07-04-2003, 03:51 AM
Thank you, but I have 2 other question:
The first is the same as the 2) I asked in my 1st post ~is there a way to set the time according to a standard international time (eg. Pacific Central Time) instead of the user's computer's time?
Secondly, is there a script to change the comments on different days (Monday, Tuesday, WED....etc) OR (1st June, 2nd June, 3rd June......) OR simply days you've set?
THANKS :)
burningstars
07-04-2003, 03:07 PM
I dont know if there is a way to set it to one specific time ill check that though and if I find anything Ill post it here!
Same for the second question too!
dandeman2k
07-04-2003, 04:08 PM
Universal Tme is programmed into javascript (or at least it was) as such you can call universal time for this script. simply replace the following line:
hr = day.getHours()
with;
hr = day.getUTCHours
I hope this helps you!!
whatever_la
07-05-2003, 05:24 AM
Hm... how do I make it in DST -0700 UTC time? i.e. The time in California, United States?
Also, how do I make the greetings change according to days?
Thanks :)
dandeman2k
07-05-2003, 11:17 AM
OK, for your first question after the line which goes "hr = day.getUTCHours" put a new line of code:
hr = hr - 7
i don't know my time zones but if this is wrong then do +7 instead.
For your second question, under this line put another line:
d = day.getDay()
now to make the message appear for each day put this in:
switch (d) {
case 1:
document.write("your monday message")
break
case 2:
document.write("your tuesday message")
break
case 3:
document.write("your wednesday message")
break
case 4:
document.write("your thursday message")
break
case 5:
document.write("your friday message")
break
case 6:
document.write("your saturday message")
break
case 7:
document.write("your sunday message")
break
}
You will obviously want to change the messaes for each day. Remember that all these lines of code have to be within script tags.
Hope this solves all your problems!
whatever_la
07-05-2003, 04:22 PM
Thanks, but when I put:
<script language="Javascript">
day = new Date()
hr = day.getUTCHours
hr = hr + 8
hr1 = hr - 12
if (hr < "1") {
document.write("Don't you think you should go to sleep? It's a bit late!!!")
}
else if (hr < "3") {
document.write("Ah! You havn't sleep yet? It's AM in the morning!!!")
}
else if (hr < "6") {
document.write("Good morning! You're up so early! ^~^")
}
else if (hr < "9") {
document.write("Good morning! Did you have your breakfast yet?")
}
</script>
It only showed the message "Don't you think you should go to sleep? It's a bit late" no matter how I changed
hr = hr + 8
to
hr = hr + 11
or to
hr = hr + 2
Whats wrong?