react-native-modal-datetime-picker 时间转化问题

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";
this.handleConfirm(date)}
     onCancel={this.hideDatePicker.bind(this)}
/>

 

你可能感兴趣的:(react,native)