0

我正在使用bootstrap datepicker,我想使用datepicker的內置函數。 我該如何使用它?如何從bootstrap datepicker得到今天的日期

$(document).ready(function() { 
    //var fromDate = $('#fromdatepicker').datepicker(); 
    var toDate = $('#datepicker').datepicker(

    ).on('change', function(e) { 
     console.log(e); 
    }); 
    // here i need current date and do some calculation and then set again. 
    console.log(toDate); 
}); 

我用這個https://bootstrap-datepicker.readthedocs.io/en/latest/index.html datepicker。它的工作正常,但我想根據我的需要做一些更改。我想獲取CurrentDate並做一些計算,然後再重新設置。我怎樣才能使用這個datepicker實現這個功能。

+0

http://www.daterangepicker.com/它可以幫助你。 –

+0

您可以使用'new Date()'在javascript中獲取當前日期。 – VincenzoC

回答

0

試試這樣說:

var toDate = $('#datepicker').datepicker(

).on('change', function(e) { 
    console.log(e); 
}); 

// here i need current date and do some calculation and then set again. 

toDate = $('#datepicker').datepicker('update',new Date()); 
console.log(toDate); 

//if want to update again 
toDate = $('#datepicker').datepicker('update','2016-08-16');