Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!