I have using react datepicker found here: https://www.npmjs.com/package/react-datepicker
My field looks like this:
<DatePicker
selected={this.state.startDate}
onChange={this.handleChangeDate}
dateFormat="yyyy-MM-dd"
/>
My handle
looks like this:
handleChangeDate = date => {
this.setState({
startDate: date
});
console.log('Start Date:' + this.state.startDate)
this.FormatDate()
};
When selecting todays date my console in the handle
gives me this:
Mon Jun 29 2020 15:36:30 GMT-0700 (Pacific Daylight Time)
The datepicker I have in a form, when saving the form it for some reason gets stored like this:
2020-06-29T20:46:42Z
How can I format the startDate
to something like this 6/29/2020 3:45PM
. I'm trying to use a library called momentjs
found here: https://momentjs.com/ . I don't need to use this library if there was a better way, but here is what I have so far:
FormatDate() {
console.log('In moment loop' + this.state.startDate);
let FormatstartDate = moment(this.state.startDate).format("yyyy-MM-dd");
console.log('Moment' + FormatstartDate);
}