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

150
Vistas
how to get upcoming time in from the list of time?

I am building a website using create-react-app and I need to get the upcoming time from the list as compared to the current time. my time list is

  let times = [
    {
      time: "05:33",
    },
    {
      time: "12:20",
    },
    {
      time: "15:23",
    },
    {
      time: "17:46",
    },
    {
      time: "19:08",
    },
  ];

I have tried many solutions but all in vain, one solution that is also unsuccessful is

  const compareTime = moment().format("hh:mm");
  time7.map((item, i) => {
    console.log(
      Date.parse(
        `01/01/2011 ${format(parse(item.time, "HH:mm", new Date()), "hh:mm")}45`
      ) > Date.parse(`01/01/2011 ${compareTime}:10`)
    );
  });

I am super stuck in this and trying to solve this problem for almost a week I need a proper solution to get the upcoming time from the list any kind of help will be appreciated.

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

0

let currentTime = new Date();
currentTime = currentTime.getHours().toString().padStart(2, '0')
+ currentTime.getMinutes().toString().padStart(2, '0');
let futureTimes = times.filter((obj) => {
    return obj.time > currentTime;
})
.sort((a, b) => {
    return a.time < b.time ? -1 : a.time > b.time;
});

let nextTime = futureTimes.length ? future times[0] : null;

I probably need to double check it and tweak, but coding on my mobile is a little tough.

Simpler solution:

let currentTime = new Date();
currentTime = currentTime.getHours().toString().padStart(2, '0')
+ currentTime.getMinutes().toString().padStart(2, '0');
let nextTime = times
.sort((a, b) => {
    return a.time < b.time ? -1 : a.time > b.time;
})
.find((obj) => {
    return obj.time > currentTime;
});
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