Add custom text to the output text field in bootstrap datetimepicker

前端 未结 2 1084
面向向阳花
面向向阳花 2020-12-21 06:19

I\'m using bootstrap 3 date/time picker here:

https://eonasdan.github.io/bootstrap-datetimepicker/

Is it possible to customise the output text in the date/ti

相关标签:
2条回答
  • 2020-12-21 06:48
    $('input').val('Departing: ' + pickedDate.toString());
    
    0 讨论(0)
  • 2020-12-21 06:51

    You have to use square brackets in your format option, because the component uses moment tokens.

    Moment docs has an Escaping characters section which states:

    To escape characters in format strings, you can wrap the characters in square brackets.

    moment().format('[today] ffffdd'); // 'today Sunday'
    

    Here is a working sample:

    $('#datetimepicker').datetimepicker({
      defaultDate:'now',
      ignoreReadonly: true,
      format: '[Departing:] DD/MM/YYYY HH:mm:ss'
    });
    <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.18.1/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="form-group" style = "margin-bottom:4px;">
        <div class='input-group date' id='datetimepicker'>
            <input type='text' class="form-control" readonly='readonly'/>
            <span class="input-group-addon" style="padding: 6px 11.5px;">
            <span class="glyphicon glyphicon-calendar"></span>
            </span>
        </div>
    </div>

    0 讨论(0)
提交回复
热议问题