onPressDate() { if (this.props.disabled) { return true; } Keyboard.dismiss(); // reset state this.setState({ date: this.getDate() }); if (Platform.OS === 'ios') { this.setModalVisible(true); } else { const {mode, androidMode, format = FORMATS[mode], minDate, maxDate, is24Hour = !format.match(/h|a/)} = this.props; // 选日期 if (mode === 'date') { DatePickerAndroid.open({ date: this.state.date, minDate: minDate && this.getDate(minDate), maxDate: maxDate && this.getDate(maxDate), mode: androidMode }).then(this.onDatePicked); } else if (mode === 'time') { // 选时间 let timeMoment = Moment(this.state.date); TimePickerAndroid.open({ hour: timeMoment.hour(), minute: timeMoment.minutes(), is24Hour: is24Hour, mode: androidMode }).then(this.onTimePicked); } else if (mode === 'datetime') { // 选日期和时间 DatePickerAndroid.open({ date: this.state.date, minDate: minDate && this.getDate(minDate), maxDate: maxDate && this.getDate(maxDate), mode: androidMode }).then(this.onDatetimePicked); } } if (typeof this.props.onOpenModal === 'function') { this.props.onOpenModal(); } }
onPressDate() { if (this.state.disabled) { return true; } // reset state this.setState({ date: this.getDate() }); if (Platform.OS === 'ios') { this.setModalVisible(true); } else { // 选日期 if (this.props.mode === 'date') { DatePickerAndroid.open({ date: this.state.date, minDate: this.props.minDate && this.getDate(this.props.minDate), maxDate: this.props.maxDate && this.getDate(this.props.maxDate) }).then(this.onDatePicked); } else if (this.props.mode === 'time') { // 选时间 let timeMoment = Moment(this.state.date); TimePickerAndroid.open({ hour: timeMoment.hour(), minute: timeMoment.minutes(), is24Hour: !this.format.match(/h|a/) }).then(this.onTimePicked); } else if (this.props.mode === 'datetime') { // 选日期和时间 DatePickerAndroid.open({ date: this.state.date, minDate: this.props.minDate && this.getDate(this.props.minDate), maxDate: this.props.maxDate && this.getDate(this.props.maxDate) }).then(this.onDatetimePicked); } else { throw new Error('The specified mode is not supported'); } } if (typeof this.props.onFocus === 'function') { this.props.onFocus(); } }
const showPicker = (field, options) => async () => { const { action, year, month, day } = await DatePickerAndroid.open(options); if (action !== DatePickerAndroid.dismissedAction) { const date = new Date(year, month, day); field.onChange(date); } };
async _togglePicker() { if(Platform.OS === 'android') { try { const {action, year, month, day} = await DatePickerAndroid.open({ date: this.state.marry_date ? new Date(this.state.marry_date) : new Date() }); if (action !== DatePickerAndroid.dismissedAction) { const {action, hour, minute} = await TimePickerAndroid.open({ hour: parseInt(moment().format("hh")), minute: parseInt(moment().format("mm")), is24Hour: false, }); if (month < 10) { month = `0${month + 1}`; } else { month = `${month + 1}`; } if (day < 10) { day = `0${day}`; } if (action !== DatePickerAndroid.dismissedAction) { if (hour < 10) { hour = `0${hour}`; } if (minute < 10) { hour = `0${hour}`; } const date = `${year}/${month}/${day} ${hour}:${minute}:00`; this.setState({ marry_date: new Date(date) }); }else { const date = `${year}/${month}/${day}`; this.setState({ marry_date: new Date(date) }); } } } catch ({code, message}) { console.warn('Cannot open date picker', message); } }else if(Platform.OS === 'ios') { this.setState({ showPicker: !this.state.showPicker }); } }
const testAsync = async () => { try { const {action, year, month, day} = await DatePickerAndroid.open(options); if (action === DatePickerAndroid.dateSetAction) { date.setFullYear(year); date.setMonth(month); date.setDate(day); const showTime = async () => { try { const {action, minute, hour} = await TimePickerAndroid.open(options); if (action === TimePickerAndroid.timeSetAction) { date.setHours(hour); date.setMinutes(minute); callback(date); } else if (action === TimePickerAndroid.dismissedAction) { // newState[stateKey + 'Text'] = 'dismissed'; } } catch (e) { throw e; } }; return showTime(); } else if (action === DatePickerAndroid.dismissedAction) { // newState[stateKey + 'Text'] = 'dismissed'; } } catch (e) { throw e; } };
_showPicker () { DatePickerAndroid .open({ date: new Date(this.state.value || this.state.intialDate || Date.now()), minDate: this.props.minDate ? new Date(this.props.minDate) : null, maxDate: this.props.maxDate ? new Date(this.props.maxDate) : null, spinnerMode: this.props.spinnerMode ? true : false }) .then(this._closePicker.bind(this)) }
async showPicker(stateKey, options) { try { const {action, year, month, day} = await DatePickerAndroid.open(options) var date = new Date(year, month, day) this.state.LaunchTime = date.toLocaleDateString() this.setState(this.state) } catch ({code, message}) { console.warn(`Error in example '${stateKey}': `, message); } }
async _show(){ try { const {action, year, month, day} = await DatePickerAndroid.open({ date: moment(this.props.date, 'YYYY-MM-DD').toDate() }); if (action !== DatePickerAndroid.dismissedAction) { this.props.onDateChange(moment({year, month, day}).format("YYYY-MM-DD")); } } catch ({code, message}) { console.warn('Cannot open date picker', message); } }
async showPicker() { let {minDate, maxDate} = this.props; const {action, year, month, day} = await DatePickerAndroid.open({ date: this.state.value, minDate, maxDate }); if (action === DatePickerAndroid.dateSetAction) { this.onDateChange(new Date(year, month, day)); } }
async showTimePickerAndroid(date : Date) { try { const {action, year, month, day} = await DatePickerAndroid.open({ date: date }); if (action !== DatePickerAndroid.dismissedAction) { TodoAction.setTime(new Date(year, month, day)); } } catch ({code, message}) { console.warn('Cannot open date picker', message); } }
showDatePickerDialog: function(options) { DatePickerAndroid.open(options).then( ({action, year, month, day}) => { if (action === DatePickerAndroid.dateSetAction) { RecordingModule.recordDate(year, month, day); } else if (action === DatePickerAndroid.dismissedAction) { RecordingModule.recordDismissed(); } }, ({code, message}) => RecordingModule.recordError(), ); },
async addDateTimeAndroid(){ try { const {action, year, month, day} = await DatePickerAndroid.open({ date: new Date(that.state.birthDay) }); if (action !== DatePickerAndroid.dismissedAction) { var date = new Date(year, month, day); that.setState({birthDay : date}); } } catch ({code, message}) { console.warn('Cannot open date picker', message); } }
async showPicker(stateKey, options) { try { var newState = {}; const {action, year, month, day} = await DatePickerAndroid.open(options); if (action === DatePickerAndroid.dismissedAction) { //newState[stateKey + 'Text'] = 'dismissed'; } else { var date = new Date(year, month, day); this._onDateChange(date); } } catch ({code, message}) { console.warn(`Error in example '${stateKey}': `, message); } }
setDate = async () => { try { const { action, year, month, day } = await DatePickerAndroid.open({ date: this.state.task.dateDue }) if (action !== DatePickerAndroid.dismissedAction) { this.setState({ task: { ...this.state.task, dateDue: new Date(year, month, day)} }) } } catch ({ code, message }) { console.warn('Cannot open date picker', message) } }
async _togglePicker(event){ try { const {action, year, month, day} = await DatePickerAndroid.open({ date: this.props.date || new Date() }); if (action !== DatePickerAndroid.dismissedAction) { this.handleValueChange(new Date(year,month,day)); // Selected year, month (0-11), day } } catch ({code, message}) { console.warn('Cannot open time picker', message); } this.props.onPress && this.props.onPress(event); }
onPress={async () => { try { const { action, year, month, day } = await DatePickerAndroid.open({ date, }) if (action !== DatePickerAndroid.dismissedAction) { // Selected year, month (0-11), day onChange(new Date( year, month, day, date.getHours(), date.getMinutes() )) } } catch ({ code, message }) { console.warn('Cannot open date picker', message) } }}
const showDate = async () => { try { const {action, year, month, day} = await DatePickerAndroid.open(options); if (action === DatePickerAndroid.dateSetAction) { date.setFullYear(year); date.setMonth(month); date.setDate(day); callback(date); } else if (action === DatePickerAndroid.dismissedAction) { // newState[stateKey + 'Text'] = 'dismissed'; } } catch (e) { throw e; } };
async onPress(){ try { const {action, year, month, day} = await DatePickerAndroid.open({ // Use `new Date()` for current date. // May 25 2020. Month 0 is January. date: moment(this.props.value, 'YYYY-MM-DD').toDate() }); if (action !== DatePickerAndroid.dismissedAction) { // Selected year, month (0-11), day this.onChange(moment({year, month, day}).format('YYYY-MM-DD')) } } catch ({code, message}) { console.warn('Cannot open date picker', message); } }
async showPicker(stateKey, options) { try { var newState = {}; const {action, year, month, day} = await DatePickerAndroid.open(options); if (action === DatePickerAndroid.dismissedAction) { newState[stateKey + 'Text'] = 'dismissed'; } else { var date = new Date(year, month, day); newState[stateKey + 'Text'] = date.toLocaleDateString(); newState[stateKey + 'Date'] = date; } this.setState(newState); } catch ({code, message}) { console.warn(`Error in example '${stateKey}': `, message); } }
setDate = (name) => { const date = new Date(this.state[name]); DatePickerAndroid.open({ date }).then(({action, year, month, day}) => { if (action !== DatePickerAndroid.dateSetAction) { return; } date.setYear(year); date.setMonth(month); date.setDate(day); this.setState(this.adjustDate(name, date)); }); }
selectDate = () => { const { onChangeDate } = this.props const { date } = this.state DatePickerAndroid.open({ date: date }).then(({ action, year, month, day }) => { if (action !== DatePickerAndroid.dismissedAction) { date.setFullYear(year) date.setMonth(month) date.setDate(day) this.setState({ date: date }) onChangeDate && onChangeDate(date) } }).catch(({ code, message }) => { }) }
async setDateAndroid() { try { const { action, year, month, day } = await DatePickerAndroid.open( { date: new Date(), maxDate: new Date(), mode: "spinner" } ); if ( action !== DatePickerAndroid.dismissedAction ) { const userBirthday = moment( new Date( year, month, day ) ).format( "YYYY-MM-DD" ); this.setDate( userBirthday ); } } catch ( { code, message } ) { console.warn( "Cannot open date picker", message ); } }
//选择日期 _onSelectDate(){ var thiz = this; DatePickerAndroid.open({ date: new Date(), minDate: new Date('1900/01/01'), maxDate: new Date('2100/12/12') }).done(function(params){ var content = ''; if(params.action !== DatePickerAndroid.dismissedAction){ content = params.year + '-' + (params.month+1) + '-' + params.day; thiz.setState({ RequiredDate:content, }); }else{ thiz.setState({ RequiredDate:'', }); } }) }
_onPressDate = async () => { const {action, year, month, day} = await DatePickerAndroid.open({ date: new Date(), minDate: new Date(), mode: 'calendar', }); if (action !== DatePickerAndroid.dismissedAction) { console.log("The year is " + String(year)); console.log("The date is " + String(month+1) + "/" + String(day) + "/" + String(year)) console.log("The day is " + convertDow(String(moment(String(month+1) + "-" + String(day) + "-" + String(year), "MM-DD-YYYY").weekday()))); this.setState({ // dateString: moment().year(year).month(month).day(day).format("MM/DD/YY"), dateString: String(month+1) + "/" + String(day) + "/" + String(year).substring(2), dateMonth: month+1, dateDay: day, dow: convertDow(moment(String(month+1) + "-" + String(day) + "-" + String(year), "MM-DD-YYYY").weekday()) }) } console.log("end of _onPressDate"); }
startDatePicker() { let today = new Date(this.state.startData); let option = { date: today }; DatePickerAndroid.open(option).then( result => { if (result.action !== DatePickerAndroid.dismissedAction) { let date = new Date(result.year, result.month, result.day); this.setState({ startData:formatter('yyyy-MM-dd',date) }); } } ).catch( error => { ToastAndroid.show("出错了",ToastAndroid.SHORT); } ); };
showAndroidPicker(){ DatePickerAndroid.open({date: this.state.date}).then(this.handleAndroidDateChange.bind(this)).done() }
}); }) }, onShow(){}, validateForm(){ if(/^\d+\.?\d?$/.test(this.state.money)&&this.state.label) return true; }, async showPicker() { var options = { date: new Date(this.state.date), maxDate: new Date() } try { const {action, year, month, day} = await DatePickerAndroid.open(options); if (action === DatePickerAndroid.dismissedAction) { } else { var date = new Date(year,month,day) this.setState({date:date,formatedDate:this.formatDate(date)}); } } catch ({code, message}) { console.warn(`Error in date picker`); } }, render() { return ( <View style={styles.container}>
onPressDate() { if (this.state.disabled) { return true; } // reset state this.setState({ date: this.getDate() }); if (Platform.OS === 'ios') { this.setModalVisible(true); } else { // 选日期 if (this.mode === 'date') { DatePickerAndroid.open({ date: this.state.date, minDate: this.props.minDate && this.getDate(this.props.minDate), maxDate: this.props.maxDate && this.getDate(this.props.maxDate) }).then(({action, year, month, day}) => { if (action !== DatePickerAndroid.dismissedAction) { this.setState({ date: new Date(year, month, day) }); this.datePicked(); } }); } else if (this.mode === 'time') { // 选时间 let timeMoment = Moment(this.state.date); TimePickerAndroid.open({ hour: timeMoment.hour(), minute: timeMoment.minutes(), is24Hour: !this.format.match(/h|a/) }).then(({action, hour, minute}) => { if (action !== DatePickerAndroid.dismissedAction) { console.log(Moment().hour(hour).minute(minute).toDate()); this.setState({ date: Moment().hour(hour).minute(minute).toDate() }); this.datePicked(); } }); } else if (this.mode === 'datetime') { // 选日期和时间 DatePickerAndroid.open({ date: this.state.date, minDate: this.props.minDate && this.getDate(this.props.minDate), maxDate: this.props.maxDate && this.getDate(this.props.maxDate) }).then(({action, year, month, day}) => { if (action !== DatePickerAndroid.dismissedAction) { let timeMoment = Moment(this.state.date); TimePickerAndroid.open({ hour: timeMoment.hour(), minute: timeMoment.minutes(), is24Hour: !this.format.match(/h|a/) }).then(({action, hour, minute}) => { if (action !== DatePickerAndroid.dismissedAction) { this.setState({ date: new Date(year, month, day, hour, minute) }); this.datePicked(); } }); } }); } else { new Error('The specified mode is not supported'); } } }