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

106
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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