Sunday, July 8, 2012

Time Example in Java Script

<html>
<head>
<script language="javascript">
var date = new Date();
var hour = date.getHours();

if(hour <= 10){
document.write("<b>Good Morning</b>");
}else if(hour >= 11 && hour <=14){
document.write("<b>Good Afternoon</b>");
}else if(hour >= 15 && hour <=18){
document.write("<b>Good Evening</b>");
}else if(hour >= 19){
document.write("<b>Good Night</b>");
}
</script>
</head>

<body>
<p>
If time on your pc is less then 10AM then you will see the Good Morning Message.<br>
else if time on you PC is from 11AM to 2PM then you will get the Good Afternoon Message.<br>
else if time on you PC is from 3PM to 6PM then you will see Good Evening Message.<br>
else if time on you PC is after 6PM then you will see Good Night Message.
</p>
</body>
</html>



output :

Good Morning

 If time on your pc is less then 10AM then you will see the Good Morning Message.

else if time on you PC is from 11AM to 2PM then you will get the Good Afternoon Message.

else if time on you PC is from 3PM to 6PM then you will see Good Evening Message.

else if time on you PC is after 6PM then you will see Good Night Message

No comments:

Post a Comment