If usage in program
<!DOCTYPE html>
<html>
<body>
<p>
Click the button <br> <br>
if the time is less than 18pm <br>
"Have a nice day" greeting. <br> <br>
If the time is greater than 18pm <br>
greeting will not be displayed. <br>
</p>
<button onclick="Function()">Click me </button>
<p id="demo"> </p>
<script>
function Function() {
var x = "";
var time = new Date().getHours();
if (time < 18) {
x = "Have a nice day";
}
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>