我有以下组件:
import React, {Component, Fragment} from 'react';
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
// import PropTypes from 'prop-types';
class Form extends Component {
state = {
selected: new Date()
}
handleChange = date => {
console.log('date: ', date)
this.setState({
selected: date
});
}
render() {
const {selected} = this.state;
return (
<Fragment>
<form>
<DatePicker
dateFormat="dd/MM/yyyy"
onChange={this.handleChange}
selected={selected}
/>
<button>search</button>
</form>
</Fragment>
);
}
}
export default Form;
当我从日期选择器中选择任何日期时,我得到以下格式:
日期:2019 年 5 月 15 日星期三 12:54:33 GMT+0100(英国夏令时间)
可以将其解析回如下格式:
2019-05-15/yyyy-mm-dd
因为我需要它以这种格式提交 API 调用?