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

105
Views
Javascript continúa desde un momento específico

Tengo un temporizador y un tiempo. El formato de tiempo es como la variable currentTime en mi código. Quiero obtener la hora actual y agregarle +1 cada segundo manteniendo el mismo formato de hora. También me gustaría restar el tiempo actual + 1: el total de horas pero manteniéndolo en tiempo real con setInterval. Espero haber sido claro en mis preguntas. Gracias.

HTML

 <button id="start">START</button> <button id="pause">PAUSE</button> <div id="output"></div>

Jav script

 const startTimeButton = document.querySelector("#start") const pauseTimeButton = document.querySelector("#pause") const output = document.querySelector("#output"); let currentTime = "12: 42: 17"; let totalHours = 30; let seconds = 0; let interval = null; const timer = () => { seconds++; // Get hours let hours = Math.floor(seconds / 3600); // Get minutes let minutes = Math.floor((seconds - hours * 3600) / 60); // Get seconds let secs = Math.floor(seconds % 60); if (hours < 10) { hours = `0${hours}`; } if (minutes < 10) { minutes = `0${minutes}`; } if (secs < 10) { secs = `0${secs}`; } return `${hours}:${minutes}:${secs}`; }; startTimeButton.addEventListener("click", () => { pauseTimeButton.style.display = "flex"; startTimeButton.style.display = "none"; console.log("START TIME CLICKED"); if (interval) { return; } interval = setInterval(timer, 1000); }); pauseTimeButton.addEventListener("click", () => { pauseTimeButton.style.display = "none"; startTimeButton.style.display = "flex"; console.log("PAUSE TIME CLICKED"); clearInterval(interval); interval = null; }); // Here is an example of what I would like to achive // currentTime + 1 (each second) // output.innerHTML = (parseInt(currentTime) + 1) - totalHours;
about 4 years ago · Juan Pablo Isaza
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!