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

220
Vistas
How to return epoch of all midnights in given time span?

I have a time span between two epoch times (in seconds). I want a function that returns the epoch times (in seconds) of all midnights within that time span.

In pseudocode I would want something like this:

const epoch_start = 1600000;
const epoch_end = 16040000;

function getMidnights(start, end){
    // do your magic    
}

console.log(getMidnights(epoch_start, epoch_end));

I would expect the return of that function to look like this: [1600020, 1600400] (these are just example values).

What would be the most efficient way to do this?

My ideas were: get unique list of days within range and return their midnight.

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

0

You might step by day rounding by day:

const epoch_start = 1600000000;
const epoch_end   = 1600400000;
const day = 86400;

function getMidnights(start, end){
    midnites = [];
    while (start < end) {
      midnites.push((start/day + .5|0)*day);
      start += day;
    }
    return midnites;
}

console.log(getMidnights(epoch_start, epoch_end))
console.log('* check it *')
console.log(getMidnights(epoch_start, epoch_end).map(t => new Date(t*1e3)));

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