Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Date Time Function

Date Time Function

Example 15

Write a JavaScript to display Good Morning, Good Afternoon or Good Evening

function Greetings() {
  var today = new Date();
  var hour = today.getHours();
  var minu = today.getMinutes();
  var sec = today.getSeconds();
  if (hour < 12) {
    console.log("Good Morning !!! Time is" + hour + ":" + minu + ":" + sec);
  } else if (hour > 12 && hour < 16) {
    console.log("Good Noon !!! Time is" + hour + ":" + minu + ":" + sec);
  } else {
    console.log("Good Day !!! Time is" + hour + ":" + minu + ":" + sec);
  }
}

Greetings();

Output:

Loading

Views: 88

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments