nz-date-picker组件时间范围限制
程序员文章站
2022-06-07 13:10:56
...
组件:
<nz-date-picker [nzFormat]="'yyyy-MM-dd'"
[nzDisabledDate]="disabledDate" style="width: 100%"
name="startDate" [(ngModel)]="formInfo.startDate"
nzPlaceHolder="请选择开始日期"></nz-date-picker>
js:
disabledDate(time) {
return time.getTime() < Date.now(); //只能选择今天过后的日期
// 一天是24*60*60*1000 = 86400000 = 8.64e7
return time.getTime() < Date.now() - 8.64e7; //只能选择今天以及今天过后的日期
return time.getTime() > Date.now(); //只能选择今天以及今天以前的日期
return time.getTime() > Date.now()-8.64e7; //只能选择今天之前的日期
let curDate = (new Date()).getTime();
let three = 90 * 24 * 3600 * 1000;
let threeMonths = curDate - three;
return time.getTime() > Date.now() || time.getTime() < threeMonths; //只能选择选择三个月之前到今天的日期
}