Tengo dos funciones en mi aplicación, una en la que obtengo la instancia del siguiente día de la semana que elijo (obtenerme el próximo día de la semana, por ejemplo), luego tengo una función que calcula los días, horas, minutos y segundos restantes.
Los días y horas restantes se calculan correctamente pero los minutos y segundos siempre son 59
Creo que esto se debe a que cuando calculo la siguiente instancia del lunes, la marca de tiempo resultante no parece tener un formato HORA:MINUTO, y quiero que sea 00:00, exactamente el comienzo del día.
nextMonday "2022-03-21T15:11:48.580Z" LOG Days: 1.999999745370371 LOG Hours: 7 LOG Minutes: 59 LOG Seconds: 59¿CÓMO PUEDO AGREGAR HORAS Y MINUTOS (00:00) a la marca de tiempo del momento que obtengo? ¡Creo que ese sería el problema!
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); };