上代码:
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>
<RangePicker
disabledDate={disabledDate}
format="YYYY-MM-DD HH:mm:ss"
/>
</div>,
document.getElementById('container'),
);