Javascript examples for Date:getUTCSeconds
If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00, create a "Good day" greeting, otherwise a "Good evening":
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// ww w. j a va 2 s.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>