Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda