简体   繁体   English

引导日期选择器的日期格式

[英]Date format for bootstrap datepicker

Hi i am using bootstrap datepicker. 嗨,我正在使用引导日期选择器。 I need to get the value from datepicker text box in the format like date-month-year to my controller but presently i am getting values like Tue Oct 01 00:00:00 IST 2013 我需要以类似date-month-year的格式从datepicker文本框中获取值,但是目前我正在获取Tue Oct 01 00:00:00 IST 2013类的值

I have tried formatting date but still i am getting same result . 我已经尝试格式化日期,但是仍然得到相同的结果。 I have tried like below 我已经尝试过如下

$(function() {
    window.prettyPrint && prettyPrint();
    $('#birthday').datepicker({
        format: "DD, d MM, yy"
    })
});

If the format attribute is not working. 如果format属性不起作用。 You can try something similar to this: 您可以尝试类似以下操作:

var dt = $('#dt').datepicker({format:'dd/mm/yyyy'}).on('changeDate', function(ev) {

   var newDate = new Date(ev.date);
   var year = newDate.getFullYear();
   var month = (newDate.getMonth()+1);
   var day = newDate.getDate();

   dt.setValue(day+'-'+month+'-'+year);
   dt.hide();

}).data('datepicker');

You are formatting your date by yourself. 您正在自己格式化日期。 You can ignore the format attribute. 您可以忽略format属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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