2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 6
|
2016-06-19 11:17:09 +08:00
|
|
|
title:
|
2016-11-11 12:08:18 +08:00
|
|
|
zh-CN: 不可选择日期和时间
|
|
|
|
en-US: Disabled Date & Time
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-12-25 01:21:03 +08:00
|
|
|
|
2016-06-19 11:17:09 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
可用 `disabledDate` 和 `disabledTime` 分别禁止选择部分日期和时间,其中 `disabledTime` 需要和 `showTime` 一起使用。
|
2015-12-25 01:21:03 +08:00
|
|
|
|
2016-06-19 11:17:09 +08:00
|
|
|
## en-US
|
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
Disabled part of dates and time by `disabledDate` and `disabledTime` respectively, and `disabledTime` only works with `showTime`.
|
2016-06-19 11:17:09 +08:00
|
|
|
|
2015-12-25 01:21:03 +08:00
|
|
|
````jsx
|
|
|
|
import { DatePicker } from 'antd';
|
2016-10-25 17:39:17 +08:00
|
|
|
const RangePicker = DatePicker.RangePicker;
|
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
function range(start, end) {
|
2016-10-25 17:39:17 +08:00
|
|
|
const result = [];
|
|
|
|
for (let i = start; i < end; i++) {
|
|
|
|
result.push(i);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
function disabledDate(current) {
|
2016-11-11 17:50:48 +08:00
|
|
|
// can not select days before today and today
|
|
|
|
return current && current.valueOf() < Date.now();
|
2016-11-11 12:08:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function disabledDateTime() {
|
|
|
|
return {
|
2016-11-14 19:13:37 +08:00
|
|
|
disabledHours: () => range(0, 60).splice(4, 20),
|
|
|
|
disabledMinutes: () => range(30, 60),
|
|
|
|
disabledSeconds: () => [55, 56],
|
2016-11-11 12:08:18 +08:00
|
|
|
};
|
|
|
|
}
|
2015-12-25 01:21:03 +08:00
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
function disabledRangeTime(_, type) {
|
2016-10-25 17:39:17 +08:00
|
|
|
if (type === 'start') {
|
|
|
|
return {
|
2016-11-14 19:13:37 +08:00
|
|
|
disabledHours: () => range(0, 60).splice(4, 20),
|
|
|
|
disabledMinutes: () => range(30, 60),
|
|
|
|
disabledSeconds: () => [55, 56],
|
2016-10-25 17:39:17 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
2016-11-14 19:13:37 +08:00
|
|
|
disabledHours: () => range(0, 60).splice(20, 4),
|
|
|
|
disabledMinutes: () => range(0, 31),
|
|
|
|
disabledSeconds: () => [55, 56],
|
2016-10-25 17:39:17 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
ReactDOM.render(
|
|
|
|
<div>
|
2016-11-14 19:13:37 +08:00
|
|
|
<DatePicker format="YYYY-MM-DD HH:mm:ss" disabledDate={disabledDate} disabledTime={disabledDateTime} showTime />
|
2016-10-25 17:39:17 +08:00
|
|
|
<br />
|
2016-11-14 11:56:05 +08:00
|
|
|
<RangePicker disabledDate={disabledDate} disabledTime={disabledRangeTime} showTime={{ hideDisabledOptions: true }} />
|
|
|
|
</div>,
|
|
|
|
mountNode
|
|
|
|
);
|
2015-12-25 01:21:03 +08:00
|
|
|
````
|