Bootstrap Timepicker init time change

17,599

Solution 1

If you don't want to use the current time (which is the one by default), you can either use the options on initialization :

$('someSelector').timepicker({defaultTime: '11:42 PM'});

Or you can use the value attribute of the input (which simplifies the initialization for several time pickers) :

<input type="text" class="myClass input-small" value="12:42 PM">
$('.myClass').timepicker({defaultTime: 'value'});

Demo (jsfiddle)

Solution 2

I'm the author the timepicker.

The 'value' option for default time has been deprecated. You have a variety of ways to set the default time to a specific value

set the value attribute

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

or set the data attribute to override the config option

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

or on init

$('#timepicker').timepicker({
    defaultValue: '12:45 AM'
});

or call the setTime method

$('#timepicker').timepicker();
$('#timepicker').timepicker('setTime', '12:45');  

Just open an issue on github if you have any problems!

Solution 3

The solution is:

var time = '@Model.MarketTime.ToString("h:mm tt")'

        $('#timepicker-default').timepicker('setTime', time);
Share:
17,599

Related videos on Youtube

user1654667
Author by

user1654667

Updated on September 16, 2022

Comments

  • user1654667
    user1654667 over 1 year

    How to dynamically change init time in Bootstrap Timepicker?

    http://jdewit.github.com/bootstrap-timepicker/

    Thanks for any help!

  • Carlos Ricardo
    Carlos Ricardo over 11 years
    I cannot use the {defaultTime: 'value'} feature.. Had to pick it up with .attr('value') :/ Any idea why? EDIT: Maybe some changes on github.com/tispratik/bootstrap-timepicker-rails
  • Sherbrow
    Sherbrow over 11 years
    @carlos you are not using the same fork of the plugin. Check the link in the question.
  • Carlos Ricardo
    Carlos Ricardo over 11 years
    I noticed that later :) Thanks
  • Krishna Rana
    Krishna Rana over 11 years
    Had the same question and can verify the {defaultTime: 'value'} works from based on the master branch commit
  • Sherbrow
    Sherbrow over 11 years
    @Johnny4000 I'm sure you mean this commit
  • kneidels
    kneidels about 11 years
    this doesnt seem to work for me... bit.ly/YjublF just posted to github - thanks!
  • Pawan Nogariya
    Pawan Nogariya about 10 years
    You wrote this $('#timepicker').timepicker({ defaultValue: '12:45 AM' }); but in your demo page you used defaultTime not defaultValue, so where it is correct? When I use defaultTime it doesn't work for me
  • Raham
    Raham over 8 years
    @jdewit please mention tha how to hide it after selection.