Javascript Date get morning or afternoon
let greeting;// w w w . j a va2 s . com let nowDate = new Date(); let nowHour = nowDate.getHours(); let nowMinute = nowDate.getMinutes(); let nowSecond = nowDate.getSeconds(); if (nowMinute < 10) { nowMinute = "0" + nowMinute; } if (nowSecond < 10) { nowSecond = "0" + nowSecond; } if (nowHour < 12) { greeting = "Good Morning"; } else if (nowHour < 17) { greeting = "Good Afternoon"; } else { greeting = "Good Evening"; } console.log(greeting + " and welcome to my website."); console.log("According to your clock the time is "); console.log(nowHour + ":" + nowMinute + ":" + nowSecond);