Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda