【问题标题】:How to get today's date from bootstrap datepicker如何从引导日期选择器获取今天的日期
【发布时间】:2016-07-27 10:51:05
【问题描述】:

我正在使用引导日期选择器,我想使用日期选择器的内置功能。 我该如何使用它?

$(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 日期选择器。它工作正常,但我想根据我的需要做一些改变。我想 getCurrentDate 并进行一些计算,然后再次设置。如何使用此日期选择器实现此功能。

【问题讨论】:

  • daterangepicker.com 可以帮到你。
  • 您可以使用new Date() 获取javascript 中的当前日期。

标签: javascript jquery twitter-bootstrap datepicker bootstrap-datepicker


【解决方案1】:

试试这样:

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');

【讨论】:

    猜你喜欢
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    相关资源
    最近更新 更多