问题描述
我有2个日历。因此,根据第一日历的选择,设置第二日历值。现在,如果第一个日历日期是今天,那么第二个日历日期将从今天开始。但我希望第二个日历日期设置为从所选日期开始的一年。例如,如果我将第一个日历日期选择为03/07/2020,则第二个日历日期必须从03/07/2021开始。
同样在输入日期后,如果我清除日期并显示出来,它将再次设置回当前日期。清除输入字段后,如何删除当前日期设置。
i have 2 calendars. So based on selection of first calendar, 2nd calendar value is been set. Now if the first calendar date is today date then the second calendar date starts from the todays date. But i want the second calendar date to set to an year from the selected date. For example, if i select first calendar date as 03/07/2020 the second calendar date must starts from 03/07/2021.Also after entering date if i clear the date and come out, it again sets back to the current date. How can i remove the current date setting when i clear the input field.
演示:
TS:
ngAfterViewInit() {
$('.effectiveOnlyDate').datetimepicker(
{ format: 'L' }).on('dp.change', (e) => {
const date = e.date.format('L');
this.date = date;
});
$('.onlyDate').datetimepicker(
{ format: 'L' }).on('dp.change', (e) => {
const date = e.date.format('L');
this.date = date;
});
$('.onlyDate').datetimepicker({
useCurrent: false //Important! See issue #1075
});
$(".effectiveOnlyDate").on("dp.change", (e) => {
const date = e.date.format('L');
this.date = date;
$('.onlyDate').data("DateTimePicker").minDate(e.date);
});
$(".onlyDate").on("dp.change", (e) => {
const date = e.date.format('L');
this.date = date;
$('.effectiveOnlyDate').data("DateTimePicker")
});
}
推荐答案
我通过选定的日期并加上一年。
I solved this by taking the selected date and adding one year to it.
$(".effectiveDate").on("dp.change", (e) => {
if (e.date) {
const date = e.date.format('L');
this.date = date;
this.datevar = e.date._d
this.datevar.setFullYear(this.datevar.getFullYear() + 1);
this.datevar;
} else {
this.date = null;
}
$('.expirationDate').data("DateTimePicker").minDate(this.datevar);
});
这篇关于如何使用带有启动日期时间选择器的angular8将日历设置为从选定日期开始的一年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!