简体   繁体   中英

Bootstrap3 datetimepicker DATE format rails

I'm using Bootstrap 3 datetimepicker in rails app. Here is my js file:

$(function() {
    $('#datetimepicker').datetimepicker();
});

And I need to reformat date type into Year-Month-Day Time

I've tried

$(function () {
    $('.datetimepicker').datetimepicker({
        format: 'yyyy-mm-dd H:i'    
    });
});

But after adding format line script doesn't work. Any ideas?

UPD

</div>
   <div class="form-group">
      <%= label_tag :start_time, 'StartTime' %>
      <div class="input-group date" id="datetimepicker">
        <%= text_field :start_time, nil, class: 'form-control' %>
        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
      </div>
    </div>

here is using

It worked for me as follows:

$('#datetimepicker').datetimepicker(
  format: 'YYYY-MM-DD HH:mm'
)

You have to specify the dateFormat and timeFormat differently. Below is the code for reference:

$('#datetimepicker').datetimepicker({
    dateFormat: "yy-mm-dd",
    timeFormat:  "HH:mm"
});

Both of the answers for this question didn't work for me. But this worked:

$('#datetimepicker').datetimepicker({
  format: 'YYYY-MM-DD HH:mm'
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM