Greeting to the User According to the Time using JavaScript

In this article I will tell you how to “welcome” any user according to the time. i.e- if time is bellow 12 then it show “Good Morning ,welcome to our website ”.if time is greater than 12 but less than 17 then it show "Good AfterNoon ,welcome to our website". if time is greater than 17 but less than 24 then it show "Good Evening, welcome to our website".

Code are:

<html>

<body>

<script>

    var welcome;

    var date = new Date();

    var hour = date.getHours();

    var minute = date.getMinutes();

    var second = date.getSeconds();

    if (minute < 10) {

        minute = "0" + minute;

    }

    if (second < 10) {

        second = "0" + second;

    }

    if (hour < 12) {

        welcome = "good morning";

    }

    else if (hour < 17) {

        welcome = "good afternoon";

    }

    else {

        welcome = "good evening";

    }

    document.write("<h2>" + "<font color='red'>" + welcome + "</font>" + " welcome to our website");

    document.write("<br>" + hour + ":" + minute + ":" + second);

</script>

</body>

</html>

Output is:

 
Ebook Download
View all
Learn
View all