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

244
Vistas
How can i reduce the "Days" to 30 in this Countdown Timer pop-up?

I have made a countdown timer pop-up with the help of google using javascript code which is set to end after 100 days, I am not able to change it to 30 days after many tries. As I am new to javascript, please help and solve my problem, also I want to know the proper logic behind this.

This is what I tried (This results as 100 days and so on hour,min, sec)

window.addEventListener("load", function(){ setTimeout( function open(event){ document.querySelector(".popup").style.display = "block"; }, 2000 ) });

document.querySelector("#close").addEventListener("click", function(){ document.querySelector(".popup").style.display = "none"; });

const year = new Date().getFullYear(); const fourthOfJuly = new Date(year, 6, 4).getTime(); const fourthOfJulyNextYear = new Date(year + 1, 6, 4).getTime(); const month = new Date().getMonth(); // countdown let timer = setInterval(function () { // get today's date const today = new Date().getTime(); // get the difference let diff; if (month > 6) { diff = fourthOfJulyNextYear - today; } else { diff = fourthOfJuly - today; } // math let days = Math.floor(diff / (1000 * 60 * 60 * 24)); let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); let seconds = Math.floor((diff % (1000 * 60)) / 1000); // display document.getElementById("timer").innerHTML = ' \ ' + days + 'days \ \ ' + hours + 'hours \ \ ' + minutes + 'minutes \ \ ' + seconds + "seconds \ "; }, 1000);

I want it to show 30 days, but how?

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

0

your code shows a countdown to the next 4th of July.

Do you want to display a countdown to a specific date or just always 30 days?

In your interval (that runs approximately each second) you compare the target date with the current date and then calculate your days, hours, minutes.

const today = new Date()

// targetDate = today + 30 days
const targetDate = new Date();
targetDate.setDate(targetDate.getDate() + 30);

const diff = targetDate.getTime() - today.getTime()

Here you can find a working version: https://jsfiddle.net/6bhuywn4/26/

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