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

165
Vistas
Convert Unix Date and Time to Local Time with JavaScript (React)

I'm trying to convert unix timestamp to local date in a react project. Below is the function that I'm using:

function convertDate(unixDate) {
        const d = new Date(unixDate * 1000);
        const day = d.toLocaleString(d.getDate())
        return(day);
    }

The date I'm getting is not acurate. For example is we run convertDate(1657745369979.82) we should get the date '07/13/2022 8:49:29 PM'. However the date that I'm actually getting is '11/10/54501, 8:59:39 AM'

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

Why are you multiplying by 1000 ? This works just fine

new Date(1657745369979.82).toLocaleString() => '14/07/2022, 02:19:29'

which is the same as

Convert epoch to human-readable date and vice versa
1657745369979.82
 Timestamp to Human date  [batch convert]
Supports Unix timestamps in seconds, milliseconds, microseconds and nanoseconds.
Assuming that this timestamp is in milliseconds:
GMT: Wednesday, July 13, 2022 8:49:29.979 PM
Your time zone: Thursday, July 14, 2022 2:19:29.979 AM GMT+05:30
Relative: A day ago
 

from https://www.epochconverter.com/

If there's more that you want, this old thread should also help Convert a Unix timestamp to time in JavaScript

about 4 years ago · Santiago Gelvez Denunciar

0

It looks like you do not need to multiply the timestamp by 1000.

Unix timestamps are often of this length: 1657831769, which would need to be multiplied by 1000 (https://www.epochconverter.com/ is useful for testing conversions).

const unixDate = 1657745369979.82;
const d = new Date(unixDate);
console.log(d.toISOString());

Output: 2022-07-13T20:49:29.979Z

about 4 years ago · Santiago Gelvez 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