How to set default time on Bootstrap timepicker

iamspauljamez picture iamspauljamez · Oct 27, 2014 · Viewed 45.4k times · Source

How can I set default time instead of current time for this datetimepicker http://tarruda.github.io/bootstrap-datetimepicker/ ?

Answer

Veve picture Veve · Oct 27, 2014

You can set the default time via JavaScript :

$('mySelector').timepicker({defaultTime: '10:45 PM'});

Or directly via the value attribute of your timepicker :

<div class="bootstrap-timepicker">
    <input id="timepicker" type="text" value="10:45 AM"/>
</div>

$('.myClass').timepicker({defaultTime: 'value'});

EDIT : was for the default timepicker of boostrap, my bad.

For your specific timepicker, it seems possible to set the datetime like this :

var picker = $('#datetimepicker').data('datetimepicker');
picker.setDate(myDate);