bootstrap datepicker today as default

前端 未结 12 2003
粉色の甜心
粉色の甜心 2020-12-24 04:32

I am using this bootstrap-datepicker for my datepicker. I\'d like the datepicker to choose \"today\" for start day or default day. I cannot figure out how to set \"today\"

相关标签:
12条回答
  • 2020-12-24 05:02

    According to this link Set default date of jquery datepicker, the other solution is

    var d = new Date();
    
    var currDate = d.getDate();
    var currMonth = d.getMonth();
    var currYear = d.getFullYear();
    
    var dateStr = currDate + "-" + currMonth + "-" + currYear;
    
    $("#datepicker").datepicker(({dateFormat: "dd-mm-yy" autoclose: true, defaultDate: dateStr });
    
    0 讨论(0)
  • 2020-12-24 05:03

    I used this a little example and it worked.

    $('#date').datetimepicker({
        defaultDate: new Date()
    });
    

    demo : http://jsfiddle.net/m2fjw57b/1/

    0 讨论(0)
  • 2020-12-24 05:04

    Set after Init

     $('#dp-ex-3').datepicker({ autoclose: true, language: 'es' });
    $('#dp-ex-3').datepicker('update', new Date());
    

    This example is working.

    0 讨论(0)
  • 2020-12-24 05:04

    For bootstrap date picker

    $( ".classNmae" ).datepicker( "setDate", new Date());
    

    * new Date is jquery default function in which you can pass custom date & if it not set, it will take current date by default

    0 讨论(0)
  • 2020-12-24 05:10

    I changed code in line 1796 file 'bootstrap-datetimepicker.js'. It's worked for me

    0 讨论(0)
  • 2020-12-24 05:13

    It works fine for me...

    $(document).ready(function() {
            var date = new Date();
            var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
    
            $('#datepicker1').datepicker({
                format: 'dd-mm-yyyy',
                orientation: 'bottom'
            });
    
            $('#datepicker1').datepicker('setDate', today);
    
        });
    
    0 讨论(0)
提交回复
热议问题