-
Welcome!
I want to welcome the user on my website depending on the current time.
I.e. it's 03:00 in the morning - a textline "Good Morning!" should be drawn by a script.
When it's 12:00 then it should say "Good Day!" and at 20:00 it should say "Good Evening!".
thx in advanced!
-
Code:
<script>
var today = new Date();
var hours = today.getHours();
if (hours == 3) document.write("Good morning!");
else if (hours == 12) document.write("Good day!");
else if (hours == 20) document.write("Good evening!");
</script>
-
P.S. If you want a range of hours, then just use < and >. For example,
Code:
<script>
var today = new Date();
var hours = today.getHours();
if (hours <= 12) document.write("Good morning!");
else if (hours <= 20) document.write("Good day!");
else document.write("Good evening!");
</script>