The timepicker addon adds a timepicker to jQuery UI Datepicker, thus the datepicker and slider components (jQueryUI) are required for using any of these. In addition all datepicker options are still available through the timepicker addon.
If you are interested in contributing to Timepicker Addon please check it out on GitHub. If you do make additions please keep in mind I enjoy tabs over spaces,.. But contributions are welcome in any form.
Download/Contribute on GitHub (Find a bug? See if its fixed here)
There is a small bit of required CSS:
/* css for timepicker */ .ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; } .ui-timepicker-div dl{ text-align: left; } .ui-timepicker-div dl dt{ height: 25px; } .ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; } .ui-timepicker-div td { font-size: 90%; }
Has this Timepicker Addon been helpful to you?
Add a simple timepicker to jQuery UI's datepicker
$('#example1').datetimepicker( { changeYear: true, dayNames:['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'], dayNamesShort:['日','一','二','三','四','五','六'], });
Show time in AM/PM 12 hour format
$('#example2').datetimepicker({ ampm: true });
Show only the time picker without date picker
$('#example3').timepicker({});
Change the format (default is "hh:mm tt")
Also related to your timeFormat, but not required, is the separator option
$('#example4').datetimepicker({ timeFormat: 'h:m', separator: ' @ ' });
Show Seconds, Minutes, or Hours
$('#example5').datetimepicker({ showSecond: true, timeFormat: 'hh:mm:ss' });
Hours, Minutes, Seconds in steps
$('#example6').datetimepicker({ showSecond: true, timeFormat: 'hh:mm:ss', stepHour: 2, stepMinute: 10, stepSecond: 10 });
Default Hours, Minutes, Seconds
$('#example7').datetimepicker({ hour: 13, minute: 15 });
Set the time range. For instance if you only want to allow the user to choose times between 8AM and 5PM.
$('#example8').timepicker({ ampm: true, hourMin: 8, hourMax: 16 });
There is also localization support. Read up on localization for datepicker for adding support for more languages. There are a few new definitions you will need to add to your language file:
Or optionally you may add them as options as shown below with Russian.
$('#example9').timepicker({ timeOnlyTitle: 'Выберите время', timeText: 'Время', hourText: 'Часы', minuteText: 'Минуты', secondText: 'Секунды', currentText: 'Теперь', closeText: 'Закрыть' });
The first approach (as documented in the datepicker documentation and mentioned above) is to create your own regional objects per region, then use the setDefaults method to tie these together. Setting datepicker and timepicker regionals separtely will help ensure proper wording when only using datepicker or timepicker. Here is an example:
$.datepicker.regional['ru'] = { closeText: 'Закрыть', prevText: '<Пред', nextText: 'След>', currentText: 'Сегодня', monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь', 'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'], monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн', 'Июл','Авг','Сен','Окт','Ноя','Дек'], dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'], dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'], dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], weekHeader: 'Не', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: '' }; $.datepicker.setDefaults($.datepicker.regional['ru']); $.timepicker.regional['ru'] = { timeOnlyTitle: 'Выберите время', timeText: 'Время', hourText: 'Часы', minuteText: 'Минуты', secondText: 'Секунды', currentText: 'Теперь', closeText: 'Закрыть', ampm: false }; $.timepicker.setDefaults($.timepicker.regional['ru']);
To show numbered grids under the sliders you may use the following options:
When using ampm option hours will be displayed with an "a" or "p": 04a, 12p, etc...
$('#example10').timepicker({ hourGrid: 4, minuteGrid: 10 });
When showing more than one month:
$('#example11').datetimepicker({ numberOfMonths: 3 });
With minDate and maxDate datepicker options:
$('#example12').datetimepicker({ numberOfMonths: 2, minDate: 0, maxDate: 30 });
Get and Set Datetime:
var ex13 = $('#example13'); ex13.datetimepicker(); $('#example13_setdt').click(function(){ ex13.datetimepicker('setDate', (new Date()) ); }); $('#example13_getdt').click(function(){ alert(ex13.datetimepicker('getDate')); });
Use the datepicker minDate/maxDate options: (note: these must use Date objects)
$('#example14').datetimepicker({ minDate: new Date(2010, 12, 20, 8, 30), maxDate: new Date(2010, 12, 31, 17, 30) });
Version 0.9.2
Last updated on 12/27/2010
jQuery Timepicker Addon is currently available for use in all personal or commercial projects under both MIT and GPL licenses. This means that you can choose the license that best suits your project, and use it accordingly.