日常
kingcwt2018-7前端antd
antd DatePicker组件 可选时间改为当前时间后5分钟
- 2023-01-04
import locale from 'antd/es/date-picker/locale/zh_CN'
import 'moment/dist/locale/zh-cn' // 时间组件改为中文展示
const disabledDate: RangePickerProps['disabledDate'] = current => {
return current && current < moment();
};
const disabledDateTime = (current:any)=>{
if(current){
let today = moment().date();
if(today == current.date()){
let minute = Number(moment().minutes())
let hour = Number(moment().hour());
let finalHour:number,finalMinute:number;
if(current.hour() > hour ){
finalMinute = 0
}else{
if(current.minute() >= 58){
finalHour = hour + 1;
finalMinute = 0;
}else{
finalHour = hour;
finalMinute = minute + 5;
}
}
return {
disabledHours: () => range(0, finalHour),
disabledMinutes: () => range(0, finalMinute)
}
}else if(moment()>current){
return {
disabledHours: () => range(0, 24),
disabledMinutes: () => range(0, 60),
disabledSeconds: () => range(0, 60)
}
}
}else{
return {
disabledHours: () => range(0, 24),
disabledMinutes: () => range(0, 60),
disabledSeconds: () => range(0, 60),
}
}
};
<DatePicker
disabledDate={disabledDate}
disabledTime={disabledDateTime as any}
onChange={()=>{}}
locale={locale}
showTime
/>