If the time is less than 20:00, create a "Good day" greeting, otherwise "Good evening": - Javascript Date

Javascript examples for Date:getUTCSeconds

Description

If the time is less than 20:00, create a "Good day" greeting, otherwise "Good evening":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from w  w w.  j a  v a  2s .  co  m
    var time = new Date().getHours();
    var greeting;
    if (time < 10) {
        greeting = "Good morning";
    } else if (time < 20) {
        greeting = "Good day";
    } else {
        greeting ="Good evening";
    }
document.getElementById("demo").innerHTML = greeting;
}
</script>

</body>
</html>

Related Tutorials