0

我使用日期/时间选择器来选择日期和时间:

var d = new Date();

$('#timePicker').datetimepicker({
    dateFormat: 'dd-mm-yyyy',
    timeFormat: 'hh:mm',
    separator: '@',
    minDate: new Date(),
    maxDate: new Date(),
});

minDate 和 maxDate 定义日期范围。不应选择过去的日期,因此当前日期是下限。

上限应为未来最多 2 个月。那么当当前月份是 11 时,我该如何处理呢?关于计算日期范围的函数有什么想法吗?

4

1 回答 1

1
var d = new Date(); // initially contains current date
var e = new Date(); // initially contains current date
                    // note: both dates must initially contain same value
e.setMonth(d.getMonth() + 2);
console.log(d);    
console.log(e);

必要时console.log更换。alert如果您想知道,这将适用于 11 月和 12 月的日期。

于 2011-01-27T10:44:15.540 回答