I have an edit form. Currently, i can fetch the inputed title and description. Here is the code
componentWillReceiveProps(newProps) {
console.log(newProps);
console.log(newProps.calendarEvent);
const { change, calendarEvent } = this.props;
if (this.state.initial) {
this.setState({ initial: false }, () => {
if (newProps.calendarEvent && newProps.calendarEvent.summary) {
change('title', newProps.calendarEvent.summary);
}
if (newProps.calendarEvent && newProps.calendarEvent.description) {
change('description', newProps.calendarEvent.description);
}
Due to that code, how can i fetch the inputed time using moment.js
If you have the DateTime in calendarEvent.start.dateTime you can first convert it into moment object
moment(calendarEvent.start.dateTime)
Then you can use it as any moment object. If you need to get the time in minutes hours AM/PM format you can do
moment(calendarEvent.start.dateTime).format('hh:mm A')
componentWillReceiveProps(newProps) {
console.log(newProps);
console.log(newProps.calendarEvent);
const { change, calendarEvent } = this.props;
if (this.state.initial) {
this.setState({ initial: false }, () => {
if (newProps.calendarEvent && newProps.calendarEvent.summary) {
change('title', newProps.calendarEvent.summary);
}
if (newProps.calendarEvent && newProps.calendarEvent.description) {
change('description', newProps.calendarEvent.description);
}
if (newProps.calendarEvent && newProps.moment(calendarEvent.start.dateTime)) {
change('hour', newProps.moment(calendarEvent.start.dateTime).format('hh:mm A'));
}
});
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.