For example, if it's between 8 and 1 pm, it would say "good morning", if it's 1:01-6:00 pm, it would say "good afternoon" and if it's between 6:01-11:59, it would say "good evening"
How do I go about doing that using javascript/jquery?
For example, if it's between 8 and 1 pm, it would say "good morning", if it's 1:01-6:00 pm, it would say "good afternoon" and if it's between 6:01-11:59, it would say "good evening"
How do I go about doing that using javascript/jquery?
Get current hour and minute like this
var d = new Date();
var curr_hour = d.getHours();
var curr_min = d.getMinutes();
You could use the Date object:
var date = new Date();
var hours = date.getHours();
if (hours >= 8 && hours < 13) {
alert('Good Morning');
} else if (hours >= 13 && hours < 18) {
alert('Good Afternoon');
} else if (hours > 18 && hours <= 23) {
alert('Good Evening');
} else {
alert('Don\'t disturb me at this lately hour');
}