I am using the following jQuery Timepicker library:
http://jonthornton.github.io/jquery-timepicker/
https://github.com/jonthornton/jquery-timepicker
I want the user to select an event at 06:00 PM up till 09.00 PM. When an user selects time picker it will start from min time to max time. Suppose a user logins at 07:12 PM, user needs to be shown date from 08:00 PM or 08:15 PM till 1 hour before the max time of 09:00 PM. If time exceeds max time, to display a sweetalert that time has exceeded maximum time. If time is earlier than min time all the time starting from 06:00 PM to 09:00 PM are displayed.
I am getting current local time in var d.
d = Date.now();
d = new Date(d);
d = (d.getHours() > 12 ? d.getHours() - 12 : d.getHours())+':'+d.getMinutes()+' '+(d.getHours() >= 12 ? "PM" : "AM");
console.log(d);
How is it possible to change min time taking into consideration local time and not to exceed max time??
As a newbie it seems to be over my head at the moment. Request from experts for help.
My Fiddle:
updated: https://jsfiddle.net/pamela_john/rh2t301w/33/
Now i have a bug which if current time is 7.01 PM and if maxtime is 07:00 PM. It will display incorrectly from 12:00 AM. Similarly for any time.
d = Date.now();
d = new Date(d);
d = (d.getHours() > 12 ? d.getHours() - 12 : d.getHours()) + ':' + d.getMinutes() + ' ' + (d.getHours() >= 12 ? "PM" : "AM");
console.log(d);
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone);
$(document).ready(function() {
$(function() {
$('input#time').timepicker('remove').timepicker({
'timeFormat': 'h:i A',
'disableTextInput': true,
'minTime': '06:00 PM',
'maxTime': '09:00 PM',
'step': 15
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.10.0/jquery.timepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.10.0/jquery.timepicker.min.css">
<input type="text" id="time" value="" class="time" />