Antd 4.x 版本 RangePicker 时间日期选择器 禁用当前时间往后的日期

<RangePicker
     format={'YYYY-MM-DD HH:mm:ss'}
     showTime={{ format: 'HH:mm:ss' }}
     disabledDate={disabledDate}
     disabledTime={disabledTime}
/>

组件

const disabledDate: RangePickerProps['disabledDate'] = (current) => {
    return current && current > moment().startOf('day');
  };

禁止选择未来的天数

function disabledTime(dates: any) {
    const hours = moment().hours();
    const minutes = moment().minutes();
    const seconds = moment().seconds();
    if (dates && moment(dates).date() === moment().date()) {
      return {
        disabledHours: () => range(hours + 1, 24),
        disabledMinutes: () => range(minutes + 1, 60),
        disabledSeconds: () => range(seconds + 1, 60),
      };
    }
    return { disabledHours: () => [], disabledMinutes: () => [], disabledSeconds: () => [] };
  }

禁止选择未来的时分秒

posted @ 2023-06-09 10:18  To_Hebe  阅读(586)  评论(0编辑  收藏  举报