pastebin

Paste Search Dynamic
Recent pastes
timer
  1. // Copyright 1999-2022. Plesk IP Holdings GmbH. All Rights Reserved.
  2. var startTimer = function(days, hours, minutes, startTime, timeShift) {
  3.     var currentDateInSeconds = Math.floor(Date.now() / 1000);
  4.     var endTime = startTime + (days * 86400) + (hours * 3600) + (minutes * 60);
  5.     var diff = Math.max(0, endTime - currentDateInSeconds - timeShift);
  6.  
  7.     displayTimerValues(diff);
  8.  
  9.     if (0 < diff) {
  10.         setTimeout(function() {
  11.             startTimer(days, hours, minutes, startTime, timeShift);
  12.         }, 1000);
  13.     }
  14. };
  15.  
  16. var displayTimerValues = function (diff) {
  17.     var currentDays = Math.floor(diff / 86400);
  18.     diff -= currentDays * 86400;
  19.  
  20.     var currentHours = Math.floor(diff / 3600) % 24;
  21.     diff -= currentHours * 3600;
  22.  
  23.     var currentMinutes = Math.floor(diff / 60) % 60;
  24.     diff -= currentMinutes * 60;
  25.  
  26.     var seconds = diff % 60;
  27.     fillTimerValue("timerResultDays", currentDays);
  28.     fillTimerValue("timerResultHours", currentHours);
  29.     fillTimerValue("timerResultMinutes", currentMinutes);
  30.     fillTimerValue("timerResultSeconds", seconds);
  31. };
  32.  
  33. var fillTimerValue = function(elementName, value) {
  34.     var element = document.getElementById(elementName);
  35.     if (element) {
  36.         element.innerHTML = (value < 10) ? "0" + value : value;
  37.     }
  38. };
Parsed in 0.007 seconds