format=(date)=>{
let mday = date.getDate();
let month = date.getMonth() + 1;
let hours=date.getHours();
let minutes=date.getMinutes();
month = month < 10 ? `0${month}` : month;
mday = mday < 10 ? `0${mday}` : mday;
hours=hours< 10? `0${hours}` : hours;
minutes=minutes< 10? `0${minutes}` : minutes;
return `${date.getFullYear()}-${month}-${mday} ${hours}:${minutes}`;
}
handleConfirm (date) {
console.log('handleConfirm', this.format(date));
let datetime=this.format(date)
this.setState({
datetime:datetime,
isDatePickerVisible:false
});
import DateTimePickerModal from "react-native-modal-datetime-picker";
<DateTimePickerModal
isVisible={this.state.isDatePickerVisible}
mode="datetime"
onConfirm={(date)=>this.handleConfirm(date)}
onCancel={this.hideDatePicker.bind(this)}
/>