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

235
Vistas
Javascript Date object keeps on returning the default date (Mon Jan 19 1970 19:18:18) when trying to convert unix time

I am trying to use the date function to convert unix time that I am trying to convert to a certain format. The function successfully returns the date in the format requested, but the time is wrong. What am I missing here?

const date = (e) => { 
  const unixTime = 1642698000
  const format = {
    weekday: 'long',
    day: 'numeric', 
    month: "2-digit", 
    year: "numeric"
  }
  return(new Date (unixTime).toLocaleString('en-US', format))
}

Expected output (app.)

Tue Jan 18 2022 17:00:00

The output recieved

Mon Jan 19 1970 19:18:18 GMT-0500 (Eastern Standard Time)

I tried following other exampled but I wasn't able to find any that would resolve this issue. I appreciate your help in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The Date constructor from Javascript accepts the number of milliseconds as timestamp, not unix time (number of seconds). So, to adjust that, is just multiply the unix time by 1000.

const date = () => { 
  const unixTime = 1642698000 * 1000
  const format = {
    weekday: 'long',
    day: 'numeric', 
    month: "2-digit", 
    year: "numeric"
  }
  return(new Date (unixTime).toLocaleString('en-US', format))
}

console.log(date())
// logs Thursday, 01/20/2022
about 4 years ago · Juan Pablo Isaza 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