+ 1
Javascript if time
Is there a way to use this code with regular time formats and not military time??? function myFunction() { var time = new Date().getHours(); var greeting; if (time < 13 ) { greeting = "David is currently in the lab writting code!"; } else { greeting = "David is not in the lab programming right now, feel free to leave a comment!!!"; } document.getElementById("status").innerHTML = greeting; } I kinda want it to be like in between the times of 7am to 11pm I'm coding....
2 Answers
+ 2
"military time" is the reqular time format for me.
Why don't you just change your if statement to
if(time > 7 && time < 13) {
//I'm coding
}
You could use this following example to use 24 hours as 12 hours system
var time = new Date().getHours();
if(time > 12) {
//It's pm
time = (time - 12) + "pm";
} else {
//It's am
time = time + "am";
}
+ 1
thank you