Javascript examples for Date:getUTCSeconds
If the time is less than 20:00, create a "Good day" greeting, otherwise "Good evening":
<!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>