简体   繁体   中英

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

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. 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.

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