Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!