<script src="https://raw.github.com/wvega/timepicker/master/jquery.timepicker.js"></script>
<h1>jQuery TimePicker Demo</h1>
<p>The dropdown starts using <code>HH:mm</code> as the timeFormat. Click the input field to see it.<p/>
<p>As of version 1.2 is easy to change the timepicker options using the <code>option</code> method. Pressing the button will change the <code>timeFormat</code> option; the function associated to the button's click event shows how.</p>
<p>Using the <code>change</code> callback several timepickers can be linked together. In this temo when a value is selected in the first timepicker it becomes the new value for startTime option of the second timepicker, constraining the elements shown in the dropdown.</p>
<br/>
<div>
<input id="tp1" class="timepicker" name="timepicker" />
<input class="change-format" data-format="HH:mm:ss p" type="button" value="Change timeFormat option to HH:mm:ss p" />
</div>
<br/><br/>
<div>
<input id="tp2" class="timepicker" name="timepicker" />
<input class="change-format" data-format="H:mm" type="button" value="Change timeFormat option to H:mm" />
</div>
<a href="http://github.com/you"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
$(document).ready(function(){
// initialize both timepickers at once
$('input.timepicker').timepicker({
timeFormat: 'hh:mm p',
// year, month, day and seconds are not important
minTime: new Date(0, 0, 0, 8, 0, 0),
maxTime: new Date(0, 0, 0, 15, 0, 0),
// time entries start being generated at 6AM but the plugin
// shows only those within the [minTime, maxTime] interval
startHour: 6,
// the value of the first item in the dropdown, when the input
// field is empty. This overrides the startHour and startMinute
// options
startTime: new Date(0, 0, 0, 8, 20, 0),
// items in the dropdown are separated by at interval minutes
interval: 10
});
// change select time in timepicker-2.
$('#tp2').timepicker().setTime('13:15');
// change select time in timepicker-1.
//
// calling the constructor on an already initialized
// timepicker will return an object with access to TimePicker
// API methods.
//
// setTime() will return the same object so it's chainable
$('#tp1').timepicker()
.setTime('11:40a')
.option('change', function(time) {
// update startTime option in timepicker-2
$('#tp2').timepicker('option', 'startTime', time);
});
$('input.change-format').click(function() {
var input = $(this),
timepicker = input.closest('div').find('.timepicker'),
instance = timepicker.timepicker();
instance.option('timeFormat', $(this).data('format'));
console.log(instance.element);
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.