Я беру дату и время отдельно, а когда я сохраняю, я хочу сохранить дату и время вместе.Поэтому, пожалуйста, предложите способ, которым я могу объединить дату и время вместе.Код, который я использую, приведен ниже.
import React, { Component, Fragment } from 'react';
import moment from 'moment';
import PropTypes from 'prop-types';
import Datetime from 'react-datetime';
import { Button, Card, CardBody, CardFooter, CardHeader, Col, Row, Form, Modal, ModalHeader, ModalBody, ModalFooter, FormGroup, Input } from 'reactstrap';
import 'react-datepicker/dist/react-datepicker.css';
import '../../../node_modules/react-datetime/css/react-datetime.css';
class NewCreation extends Component {
constructor(props) {
super(props);
this.state = {
startDate: moment(),
startTime: moment(),
endDate: moment(),
endTime: moment(),
};
this.submitClick = this.submitClick1.bind(this)
}
handleStartDate(date) {//selectedDate:moment()
this.setState({startDate: moment(date).format('LL')});
this.forceUpdate()
}
handleStartTime(time) {
this.setState({ startTime: moment(time).format('HH:mm:ss') });
this.forceUpdate()
}
handleEndDate(date) {
this.setState({ endDate: moment(date).format('LL') });
this.forceUpdate()
}
handleEndTime(time) {
this.setState({ endTime: moment(time).format('HH:mm:ss') });
this.forceUpdate()
}
// SAVING Details
submitClick(e){
//on saving i wish to save the date and time together like ---> "2018-10-30 00:00:00.000"
}
render() {
return (
<Row>
<Col md="12">
<Form action="" method="post" encType="multipart/form-data" className="form-horizontal">
<FormGroup row>
<Col md="3"><span>Start Date</span><Datetime dateFormat={true} timeFormat={false} onChange={this.handleStartDate.bind(this)}/></Col>
<Col md="3"><span>Start Time</span><Datetime dateFormat={false} timeFormat={true} onChange={this.handleStartTime.bind(this)}/></Col>
<Col md="3"><span>End Date</span><Datetime dateFormat={true} timeFormat={false} onChange={this.handleEndDate.bind(this)}/></Col>
<Col md="3"><span>End Time</span><Datetime dateFormat={false} timeFormat={true} onChange={this.handleEndTime.bind(this)}/></Col>
</FormGroup>
</Form>
<div className="card-header-actions">
<Button type="button" size="sm" color="primarydark" onClick={this.submitClick}><i className="fa fa-dot-circle-o"></i> <span>Save And Continue</span></Button>
</div>
</Col>
</Row>
);
}
}
export default NewCreation;
Я использую response-datetime для выбора даты и времени.