Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript to Output Text Based on User's Current Time

I don't know JavaScript, but I am familiar with following directions. I know a little PHP.

I'm looking for a piece of JS that will output a particular string of text for my header, based on the user's current time.

For example:

12:00AM - 12:00PM - Good Morning!   12:00PM - 6:00PM - Good Afternoon!   6:00PM - 12:00AM - Good Evening! 
like image 401
Mike Meldrem Avatar asked Nov 06 '12 05:11

Mike Meldrem


People also ask

How do you print something in JavaScript?

JavaScript does not have any print object or print methods. You cannot access output devices from JavaScript. The only exception is that you can call the window.print() method in the browser to print the content of the current window.


1 Answers

Try following piece of Javascript code:

var today = new Date() var curHr = today.getHours()  if (curHr < 12) {   console.log('good morning') } else if (curHr < 18) {   console.log('good afternoon') } else {   console.log('good evening') } 
like image 176
Chinmayee G Avatar answered Oct 10 '22 05:10

Chinmayee G