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

123
Visualizações
How to convert Firebase timestamp to local date in Next.js?

I'm trying to convert Firebase timestamp to local date without success. I'm getting Invalid Date with the code below. What am I doing wrong with toLocaleString or is there other methods?

<Table.Header>
  <Table.Column>Email</Table.Column>
  <Table.Column>Last login</Table.Column>
  <Table.Column>Created</Table.Column>
</Table.Header>
<Table.Body>
  {usersList.map((user, index) => (
    <Table.Row key={index}>
      <Table.Cell>{user.user.email}</Table.Cell>
      <Table.Cell>{new Date(user.user.lastLoginAt).toLocaleString("da-DK", {year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit",})}</Table.Cell>
      <Table.Cell>{new Date(user.user.createdAt).toLocaleString("da-DK", {year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit",})}</Table.Cell>
    </Table.Row>
  ))}
</Table.Body>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The issue occurs because both lastLoginAt and createdAt values come as strings from your API data. You need to convert them to a number so they can be used inside the new Date() call.

new Date(Number(user.user.lastLoginAt))
new Date(Number(user.user.createdAt))

The Date constructor expects the timestamp value to be a number.

Time value or timestamp number

value

An integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC (the ECMAScript epoch, equivalent to the UNIX epoch), with leap seconds ignored. Keep in mind that most UNIX Timestamp functions are only accurate to the nearest second.

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