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

251
Vistas
Get human readable time from react native datetime picker
import React from 'react';
import { Text, Button } from 'react-native';
import RNDateTimePicker from '@react-native-community/datetimepicker';

const Timer = ({}) => {
    const [picker, setPicker] = React.useState({time: null, date: null});
    const [mode, setMode] = React.useState(null);

    const setTimer = (event, time) => {
         if (mode == 'date') {
             if (time) setPicker(e => ({...e, date: time}));
             setMode('time');
         } else if (time && picker.date ) {
             setPicker(e => ({...e, time: time}));
             // do something here   
        }
    }

    const humanReadable = () => {/* return human readable date time format (2022/05:31 13:59:00) */}

    return (
        <>
             <Text>{ humanReadable() }</Text>
             <Button value="Get Date & Time" onPress={() => setMode("date")} />
             { 
                 mode && (
                     <RNDateTimePicker 
                           onChange={setTimer} 
                           mode={mode}
                           display={mode=='date' ? "calendar" : "clock"}
                           themeVariant="light" 
                           value={picker[mode] ?? new Date()} 
                     />
                 )
             }
        </>
    )
}

Beacuse i m working on android. So i have no option for set mode "datetime". That is why i have added here this. My question is how to get human readable datetime

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Maybe look at this lib https://date-fns.org

Here's how I use it :

//IMPORT FIRST 
import { format } from 'date-fns';
import { fr } from 'date-fns/locale';

//THEN IN YOUR JSX
           <Text>
           {format(dateValue, 'dd MMMM yyyy', { locale: fr })}
           </Text>
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use moment.js

Its an amazing module to format date. Please have a look at it.

For your format you can do something like,

import moment from 'moment';

moment().format("YYYY/MM/DD hh:mm:ss");

about 4 years ago · Juan Pablo Isaza 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