我正在创建一个包含2个(开始和结束)DatePicker
的表单,并且一切正常:我可以选择日期,然后在状态下使用该值(具有功能)。我的问题是,选择日期时,它在字段中无法正确显示。
它应该看起来像这样:December 6, 2019 4:00 PM
,但实际上看起来像这样:Dec
您只能看到前3个字符。
我该如何解决?我尝试从字段props
中获取值并将其插入到selected属性中,但是它不起作用-它始终仅显示前3个字符。
这是我现在拥有的代码:
render() {
const placeholder = this.props.name === "start" ? "From" : "To";
const { showTime, value } = this.props
console.log(moment(value).format('LLL'))
return (
<div className="date-picker">
<DatePicker
timeFormat="HH:mm"
selected={value ? new Date(moment(value).format('LLL')) : this.state.startDate}
onChange={this.handleChange}
showTimeSelect={showTime}
dateFormat="LLL"
dropDownMode="select"
placeholderText={placeholder}
/>
</div>
);
}
}
答案 0 :(得分:1)
只需更改此:
dateFormat =“ LLL”
收件人
dateFormat="MMMM d, yyyy h:mm aa"
您在react-datepicker中使用了 moment 库格式
要了解有关react-datepicker格式的更多信息,请转到here