【发布时间】:2018-09-23 08:34:49
【问题描述】:
我正在尝试使用moment 在react-datepicker 组件中设置minDate 属性:
if(this.props.minDate){
console.log('date:' + moment(this.props.minDate)); //1517436000000
return <DatePicker
minDate={ new moment(this.props.minDate)}
selected={this.state.startDate}
onChange={this.handleChange}
disabled = {this.props.disabled}
/>
或new Date:
console.log('new date:' + new Date(this.props.minDate)); // Thu Feb 01 2018 02:00:00 GMT+0200
return <DatePicker
minDate={ new Date(this.props.minDate)}
selected={this.state.startDate}
onChange={this.handleChange}
disabled = {this.props.disabled}
/>
我的 minDate 字符串 - "2011-10-01"。
结果仍然是当天,控制台中没有错误,感谢您的帮助。
【问题讨论】:
-
这是定制的 DatePicker 还是您使用 AirBnB 组件或其他什么...?
标签: javascript reactjs datepicker momentjs