I have two nav-pills that I need to hide until a certain time of the day and then hide again at a later time of the same day. However there is a third nav-pill which shouldn´t be affected by this and visible at all times.
function showNavPill() {
let now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
if (date > 15.30 && date < 17.15) {
nav-pill.show = true;
} else {
nav-pill.show = false;
}
}
showNavPill();
I´m quite new to this so not sure if this makes any sense?
In your example you compare a undefined variable
datewith two float values15.30and17.15. So let us definedateand we will have a chance to get it working.I simply added
const date = hours + (minutes / 100);to converthoursandminutesinto a float value that may match your conditions.As a result
nav-pill.showwill betruebetween15:31:00and17:14:59(local time!) of your visitor.But please make yourself aware that
nav-pillis not a valid name for a variable in javascript!