Greeting message according to time

Abhisek
Posted by Abhisek under JavaScript category on | Views : 10020
The following javascript will display greeting message like, Good Morning, Good Afternoon and Good Evening according to the time.


<html>
<head>
<title>Messages
</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
currentTime=new Date();
//getHour() function will retrieve the hour from current time
if(currentTime.getHours()<12)
document.write("Good Morning");
else if(currentTime.getHours()<17)
document.write("Good Afternoon");
else
document.write("Good Evening");
//End of JavaScript functions
</SCRIPT>
</body>
</html>



It will display 'Good Morning' if you run it between 12o'clock. After 12o'clock till 5pm it will display 'Good Afternoon' and after 5pm it will display 'Good Evening' on the web browser. You can embed this code in your webpage to greet a user according to time automatically.

Comments or Responses

Login to post response