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

95
Views
Calcule la diferencia de tiempo entre los clics de dos botones usando JS

Tengo dos botones asp.net y quiero calcular la diferencia de tiempo entre los clics de los botones usando JS

Botón 1 - Inicio
Botón 2 - Siguiente

Primero obtuve la hora actual al hacer clic en el botón "Inicio" en la función getStartTime(). y de manera similar para el segundo botón en la función getEndTime().

Para calcular la diferencia horaria, uso otra función: calcular la diferencia () y llamo a las funciones anteriores. Quiero calcular la diferencia después de hacer clic en el botón "Siguiente". El problema es que getStartTime() está calculando la hora actual cada vez. como puedo

¿Almaceno el tiempo del clic del botón en una variable y lo devuelvo a otra función?

 var startTime, startHour, startMin, startSec, endTime, endHour, endMin, endSec, diffTime, stTime, etTime; //To Get the click time of Start Button(btnStart_OnClick) function getStartTime() { startTime = new Date(); startHour = startTime.getHours(); startMin = startTime.getMinutes(); startSec = startTime.getSeconds(); if (startHour > 0) { startHour = startHour * 3600; } if (startMin > 0) { startMin = startMin * 60; } stTime = startHour + startMin + startSec; return stTime; } //To get the click time of Next Button function getEndTime() { endTime = new Date(); endHour = endTime.getHours(); endMin = endTime.getMinutes(); endSec = endTime.getSeconds(); if (endHour > 0) { endHour = endHour * 3600; } if (endMin > 0) { endMin = endMin * 60; } etTime = endHour + endMin + endSec; return etTime; } function calculateDifference() { var start = getStartTime(); // On calling this function, current date is returned instead of the click time of 'Start' button var end = getEndTime(); var diff = end - start; return diff; } //Button Next_OnClick function newTimeLeft() { var difference = calculateDifference(); var newTimeLeft = 1800 - difference; if (newTimeLeft > 0) { javascript_countdown.init(newTimeLeft, 'javascript_countdown_time'); } }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si necesita diferencias de tiempo entre dos clics de botón, es mejor que realice un seguimiento de las dos marcas de tiempo. Luego diferencie entre dos, supongo que esto debería funcionar:

 let startTime, endTime; function getStartTime() { startTime = new Date().getTime() } function getEndTime() { endTime = new Date().getTime() } function calculateDifference() { return startTime - endTime; }

Llamar calculateDifference() devolverá la diferencia de tiempo en milisegundos. El descanso depende de ti.

Espero que esto ayude.

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!