Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
Get selected date from ReactNative-DatePickerAndroid

I am following ReactNative DatePickerAndroid Docs. For DatePickerIOS we have onDateChange method.

Is there any similar method to get selected date from DatePickerAndroid? Above documentation didn't mention any code example to get selected date.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can get selected date in showPicker method from given code example :

showPicker = async (stateKey, options) => {
    try {
      var newState = {};
      const {action, year, month, day} = await DatePickerAndroid.open(options);
      if (action === DatePickerAndroid.dismissedAction) {
        newState[stateKey + 'Text'] = 'dismissed';
      } else {
        // <<<< Newly selected date >>>>
        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);
    }
  };
render() {
   return (
   <TouchableWithoutFeedback
    onPress={this.showPicker.bind(this, 'spinner', { date: this.state.presetDate })}>
     <View>
        <Text style={styles.text}>Date selector</Text>
     </View>
   </TouchableWithoutFeedback>
  )
}
over 4 years ago · Santiago Trujillo Denunciar

0

As we can see the example code on documentation, create an async function, this function will handle promise data, and trigger this function to you component Text with onPress function or TexInput with onFocus function. example:

async _onMyDatePress(){
   try {
            const {action, year, month, day} = await DatePickerAndroid.open({           
                date: new Date()
            });

            if(action == DatePickerAndroid.dateSetAction){
                console.log(year + ' ' + month + ' ' + day);
            }

        } catch ({code, message}) {
            console.warn('Cannot open date picker', message);
        }   
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda