Home >Web Front-end >JS Tutorial >JavaScript method to display greetings based on time period_javascript skills
The example in this article describes the method of using JavaScript to display greetings based on time periods. Share it with everyone for your reference. The specific implementation method is as follows:
Add the following code between 6c04bd5ca3fcae76e30b72ad730ca86d36cc49f0c466276486e50c850b7e4956 in HTML:
<script language="javaScript"> <!-- now = new Date(),hour = now.getHours() if(hour < 6){document.write("凌晨好!")} else if (hour < 9){document.write("早上好!")} else if (hour < 12){document.write("上午好!")} else if (hour < 14){document.write("中午好!")} else if (hour < 17){document.write("下午好!")} else if (hour < 19){document.write("傍晚好!")} else if (hour < 22){document.write("晚上好!")} else {document.write("夜里好!")} // --> </script>
I hope this article will be helpful to everyone’s JavaScript programming design.