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

122
Vistas
get epoch time in js using new date for 7 days back midnight in javascript?

I am trying to get 7 days back epoch 12 am time but I am getting 7 days back time but same as the time at present like at 5 pm it gives 7 days back but at 5pm istead of 12 am. below code is what I tried:

  let createdAt = new Date();
 createdAt = new Date().setDate(createdAt.getDate()-7);

please help me to understand , how to get 12 am of 7 days back?, thanks in advance.

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

0

You need to zero the time too, e.g.

let createdAt = new Date();
createdAt.setHours(0,0,0,0);
createdAt = new Date().setDate(createdAt.getDate()-7);

The last line could also be:

createdAt = createdAt.setDate(createdAt.getDate() - 7);

since the set methods return the time value of the updated date.

Or create a new Date from just the date parts and get its time value, e.g.

let d = new Date();
let ms = new Date(d.getFullYear(), d.getMonth(), d.getDate() - 7).getTime();

console.log(ms + '\n' + new Date(ms).toString());

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