最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap3 datetimepicker DATE format rails - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question edited May 30, 2015 at 9:22 Damir Nurgaliev asked May 30, 2015 at 8:39 Damir NurgalievDamir Nurgaliev 3615 silver badges20 bronze badges 1
  • try it as follows: $('#datepicker').datetimepicker({ format:'d.m.Y H:i' }); – Adnan Devops Commented May 30, 2015 at 8:44
Add a ment  | 

3 Answers 3

Reset to default 3

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'
})
发布评论

评论列表(0)

  1. 暂无评论