前言
本文章主要功能是实现不能选中当前时间以前的时间:即不能选中此刻之前的时间,比如此刻是2018年10月11日15:18,那么2018年10月11日15:18分之前的所有时间都不能选,包含时分。 如有疑问,欢迎留言交流!
代码
const { DatePicker, Row } = antd;
class limitTime extends Component{
state={
currentTime:null,
}
render(){
<Row>
<DatePicker
disabledDate={this.disabledEndDate}
showTime={{ format: 'HH:mm' }}
format="YYYY-MM-DD HH:mm"
onOpenChange={this.handleEndOpenChange}
/>
</Row>
}
disabledEndDate = (endValue) => {
let me = this;
const startValue = this.state.currentTime;
if (!endValue || !startValue) {
return false;
}
return endValue.valueOf() <= startValue.valueOf();
}
handleEndOpenChange = (open) => {
let me = this
if(open){
me.currentTime = moment();
}
this.setState({currentTime:moment() });
}
componentDidMount(){
}
componentDidUpdate(){
}
componentWillUnmount(){
}
}