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

135
Visualizações
remaining minutes and seconds to date are always 59 with moment

I have two functions in my app, one where I get the instance of the next weekday I choose (get me next mindayfor example), then I have a function which calculates remianing days,hours,minutes and seconds.

Days and hours remaining are calculated correctly but minutes and seconds are always 59

I think this is because when I calculate next instance of monday the resulting timestamp doesn't appear to have a HOUR:MINUTE format, and I want it to be 00:00, so exactly start of the day

nextMonday "2022-03-21T15:11:48.580Z"

 LOG  Days:  1.999999745370371
 LOG  Hours:  7
 LOG  Minutes:  59
 LOG  Seconds:  59

HOW CAN I ADD HOURS AND MINUTES (00:00) to the moment timestamp I get, I think that would be the problem!

let nextThursday = getNextThursday();
getCountdown();

const getNextDay = () =>
    {
        const dayINeed = 7; // for monday
        const today = moment().isoWeekday();

        // if we haven't yet passed the day of the week that I need:
        if (today <= dayINeed) { 
        // then just give me this week's instance of that day
        return moment().isoWeekday(dayINeed);
        } else {
         // otherwise, give me *next week's* instance of that same day
        return moment().add(1, 'weeks').isoWeekday(dayINeed);
        }
    };

   const getCountdown = (ending) => {
    var now = moment();
    var end = moment(ending); // another date
    var duration = moment.duration(end.diff(now));
  
    //Get Days and subtract from duration
    var days = duration.days();
    duration.subtract(days, 'days');
  
    //Get hours and subtract from duration
    var hours = duration.hours();
    duration.subtract(hours, 'hours');
  
    //Get Minutes and subtract from duration
    var minutes = duration.minutes();
    duration.subtract(minutes, 'minutes');
  
    //Get seconds
    var seconds = duration.seconds();
    console.log("Days: ", days);
    console.log("Hours: ", hours);
    console.log("Minutes: ", minutes);
    console.log("Seconds: ", seconds);
  };
about 4 years ago · Juan Pablo Isaza
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