javascript implements a method of displaying greetings based on time periods

  • 2020-06-19 09:37:30
  • OfStack

This article illustrates the javascript implementation of displaying greetings based on time periods. Share to everybody for everybody reference. Specific implementation methods are as follows:

Add the following code to HTML's < body > < /body > Between:


<script language="javaScript">
<!--
now = new Date(),hour = now.getHours()
if(hour < 6){document.write(" Good in the morning !")}
else if (hour < 9){document.write(" Good morning !")}
else if (hour < 12){document.write(" Good morning !")}
else if (hour < 14){document.write(" good afternoon !")}
else if (hour < 17){document.write(" Good afternoon, !")}
else if (hour < 19){document.write(" Good evening !")}
else if (hour < 22){document.write(" Good evening !")}
else {document.write(" Good night !")}
// -->
</script>

I hope this article has been helpful for your javascript programming.


Related articles: