This time I will share jQuery Plugin and tutorial about Check If Current Time Falls Within A Specific Date Range – Now Open, hope it will help you in programming stack.
Now Open is a small jQuery plugin that makes it possible to check if current time falls in a time range you specify. Supports week days and exclude days/times. Typical use cases for this plugin include live chat, customer service and more.
Basic usage:
1. Insert jQuery library and the jQuery Now Open plugin’s script into the html file:
1 |
< script src = "//code.jquery.com/jquery.min.js" ></ script > |
2 |
< script src = "js/now_open.js" ></ script > |
2. Set the datetime range and exclude days/times as these:
3. Initialize the plugin by calling the function on the desired element.
1 |
$('#element').now_open({ |
4. Do something if the current time is in the datetime range.
01 |
$( '#element' ).now_open({ |
06 |
function myCallback(element, isOpen){ |
08 |
element.html( '<i class="fa fa-phone-square"></i> We are open... call us!' ); |
10 |
element.html( '<i class="fa fa-phone-square"></i> Live Chat Offline' ); |
5. Set the latency time in minutes to keep checking the current time.
1 |
$( '#element' ).now_open({ |
6. You can also specify the current time instead of the local time.
1 |
$( '#element' ).now_open({ |
6 |
currentDate: "June 9, 2017 11:00:00" |
This awesome jQuery plugin is developed by alotropico. For more Advanced Usages, please check the demo page or visit the official website.