Trying to use HTML / JS to display something like this: It's Monday 11:03 AM — We are currently open
I have tried a few different things but, can only get this to work partially. I want to show weekday/time of day/ and if the shop is open or closed.
These would be the hours:
Monday 10 a.m. - 5 p.m.
Tuesday 12 - 7 p.m.
Wednesday 10 a.m. - 5 p.m.
Thursday 10 a.m. - 5 p.m.
Friday 10 a.m. - 5 p.m.
Saturday 10 a.m. - 2 p.m.
Sunday Closed
function getDayOfWeek(date) {
const dayOfWeek = new Date(date).getDay();
var dateWithouthSecond = new Date();
dateWithouthSecond.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
return isNaN(dayOfWeek) ? null :
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek];
}
document.getElementById("demo").innerHTML = ( "It's " + getDayOfWeek(Date.now()) );