Search code examples
twitter-bootstrap-3bootstrap-datetimepickereonasdan-datetimepicker

Bootstrap 3 Datepicker v4 Docs 24 hours time format


I am using https://eonasdan.github.io/bootstrap-datetimepicker/ and is it possible to cofigure to use 24 hours format?

Nowadays I use it like this but it is not what I need

$('.dayWorkTime').datetimepicker({
    format: 'LT' 
});

Solution

  • Yes, you have to set format to HH:mm.

    As the docs says:

    See momentjs' docs for valid formats. Format also dictates what components are shown, e.g. MM/dd/YYYY will not display the time picker.

    Here a working example:

    $("#datetimepicker1").datetimepicker({
      format: 'HH:mm'
    });
    <link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
    <link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
    
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
    
    <div class="input-group date" id="datetimepicker1">
      <input type="text" class="form-control" />
      <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
      </span>
    </div>