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

135
Visualizações
React Native map function to get date drom database

I would like to display the date form my database (firestore) on my frontend but it only gives me seconds and nanoseconds as values when it clearly correct in the database.

I am doing a map function to get the data from the database.

<Text style={styles.datecon}>{comp.date.seconds}</Text>

The above code works but gives me a string of all the seconds.

<Text style={styles.datecon}>{comp.date}</Text>

The above code doesn't work due to it being an object and needs to be expanded but I can onlyu expand it to seconds and nanoseconds.

Console.log

Here is where I console.log the data

Firestore

Here is the data in firestore

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Create a function to convert seconds to date.

const convertToDate = (seconds) => {
    return new Date(seconds).toString();
}

Then use it in your jsx.

<Text style={styles.datecon}>{convertToDate(comp.date.seconds)}</Text>
about 4 years ago · Juan Pablo Isaza Relatório

0

Thanks to the answer (from bgcodes) I mahnage to fix the error and also fixing the date to not say 1970 you should just *1000 to get the correct date

const convertToDate = (seconds) => {
    return new Date(seconds*1000).toString();
}
<Text style={styles.datecon}>{convertToDate(comp.date.seconds)}</Text>
about 4 years ago · Juan Pablo Isaza Relatório

0

What you get from the SDK is a Firestore-specific type called a Timestamp, which has helpful methods listed here.

One of these is to get a Date object from the timestamp, which you'd do with , much simpler with:

<Text style={styles.datecon}>{comp.date.toDate()}</Text>
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