Search code examples
jquerytimetimepicker

jQuery Timepicker - Every 15 minutes


I am using jQuery Timepicker as follows:-

// Time Picker Function

$(function() {
    $('#time').timepicker({ 'scrollDefault': 'now','timeFormat': 'H:i', stepMinute: 15 });

  var coeff = 1000 * 60 * 15;
  var date = new Date();  //or use any other date
  var rounded = new Date(Math.round(date.getTime() / coeff) * coeff);

  $('#time').timepicker('setTime', rounded);

});

In the options object, I've tried setting interval: 15 and stepMinute: 15. By default, the dropdown shows the time in 30 minute intervals. I'm trying to change that to 15 minute intervals. Is there a way I can change this?


Solution

  • According to the GitHub site, there is no stepMinute option. I did, however see a step option. That's most likely what you're looking for and will solve this issue

    step The amount of time, in minutes, between each item in the dropdown. Alternately, you can specify a function to generate steps dynamically. The function will receive a count integer (0, 1, 2...) and is expected to return a step integer. default: 30

    https://github.com/jonthornton/jquery-timepicker

    Edit: It's important to include these two files

    <link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.min.css" />
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.min.js"></script>