当前位置: 代码迷 >> 综合 >> antDesign RangePicker限制日期可选范围
  详细解决方案

antDesign RangePicker限制日期可选范围

热度:84   发布时间:2023-10-27 13:22:51.0

上代码:


import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import moment from 'moment';
import { DatePicker } from 'antd';const { RangePicker } = DatePicker;function disabledDate(current) {// 限制为前后一周return current < moment().subtract(7, "days") || current > moment().add(7, 'days')// 限制为前后一周// return current < moment().subtract(1, "weeks") || current > moment().add(1, 'weeks')// 限制为前后一月// return current < moment().subtract(1, "months") || current > moment().add(1, 'months')// 限制为前后一年// return current < moment().subtract(1, "years") || current > moment().add(1, 'years')
}ReactDOM.render(<div><RangePickerdisabledDate={disabledDate}format="YYYY-MM-DD HH:mm:ss"/></div>,document.getElementById('container'),
);