Set Default Date Bootstrap Datepicker

前端 未结 9 1273
暗喜
暗喜 2021-02-12 14:15

How to set a default date in Bootstrap Datepicker?

I want to set a date : 24/12/2006

When I open datepicker it should show me this date select on calender.

9条回答
  •  天涯浪人
    2021-02-12 15:04

    I wanted to set a date at the startup, and the mentionned methods didn't work. The date was shown, but when I clicked on the object the date was not selected.

    So what I did is retrieving the Datepicker object of the library, and apply the _setDate method on it :

    $('#dob').data("datepicker")._setDate(date);
    

    But for this to work, the date object must be at midnight on UTC time, so before I did :

    var date = new Date();
    date.setUTCHours(0,0,0,0);
    

    And then it worked.

提交回复
热议问题