Pre:用到了moment,先添加
<DatePicker
disabledDate={disabledDate}
format="YYYY-MM-DD"
/>
禁止当天之前的时间:
//主要是拿current去做比较,得到一个时间段
const disabledDate = (current)=> {
//当天之前的不可选,不包括当天
return current && current < moment().subtract(1,"days");
//当天之前的不可选,包括当天
//return current && current < moment().endOf(‘day');
}
禁止当天之后的时间
//不可选择当天之后的时间
const disabledDate =(current)=>{
//moment做一些限定, 选择时间要大于等于当前天。若今天不能被选择,去掉等号即可。
return current && current >= moment().endOf('day');
}