Show DIV at specific times of the day (useful for showing "open hours" on a website)
I would like to create a function on my site so that I can show when my physical store is open.
I need to switch DIV visibilty based on time.
For example: 07: 00-15: 59 = Show div 16: 00-06: 59 = Hide div
I have really good knowledge in html5 and less. I can do simple things in jquery and php. I thought like crazy, but I can't find anything.
If there is anyone who can just point me in the right direction, I would be very happy.
Thanks to the good people :)
+3
source to share
4 answers
You can use the following to get the system time:
var date = new Date();
var time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
$('div').hide()
if(date.getHours()>7&&date.getHours()<16){
$('div').show()
}
else
if(date.getHours()>=16&&date.getHours()<7){
$('div').hide()
}
+1
source to share
You can compare the current time with the time you need to show a specific div using jquery like this:
$('#mydiv').hide();
$('#myclosediv').hide();
if(today.getHours() >= 7 && today.getHours() < 16){
$('#myopendiv').show();
}
else{
$('#myclosediv').show();
}
If the current time is between 7:00 am and 4:00 pm, then a div with id 'myopendiv' will be shown. Another div.
+1
source to share