我在反应原生应用程序中使用native datepicker of android,只有当我使用调试模式时才会获得日期,但是当我使用真实手机取消调试模式时,我会在调试时选择同一日期警报 'invalid date' .
showDatePicker = async () => {
if (Platform.OS === 'ios') {
this.setState({ datePickerIosPlatform: true })
} else {
try {
const { action, year, month, day } = await DatePickerAndroid.open({
date: new Date()
});
if (action !== DatePickerAndroid.dismissedAction) {
console.log('action', action, 'year', year, ' month', month, 'day', day)
var stringDate = `${year} ${month} ${day}`;
var newDate = new Date(stringDate)
alert(newDate)
var convertDate = moment(newDate).format('DD.MM.YYYY')
console.log('convertdata',convertDate)
// this.convertDate(stringDate)
}
} catch ({ code, message }) {
console.warn('Cannot open date picker', message);
}
}
}