jsumell

Timer_Counter

Feb 3rd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*This Javascript counts down the timer to the zero
  2. * and release the wanted String after timer is zero. */
  3.  
  4. function generoi() {
  5.   var month = document.getElementById('monthValue').value;
  6.   var year = document.getElementById('yearValue').value
  7.   var day = document.getElementById('dayValue').value;
  8.   laskuri(day, month, year);
  9.  
  10.   //document.getElementById("generated").innerHTML = "Hello World!," +day +"." +month +"." +year;
  11. }
  12.  
  13.  
  14. function laskuri(day, month, year) {
  15. var mjono = ""
  16.  
  17. // Set the date we're counting down to
  18. var ajankohta = "" +month +" "+day +", " +year +" 00:00:00";
  19. var countDownDate = new Date(ajankohta).getTime();
  20.  
  21. // Update the count down every 1 second
  22. var x = setInterval(function() {
  23.  
  24.   // Get todays date and time
  25.   var now = new Date().getTime();
  26.  
  27.   // Find the distance between now and the count down date
  28.   var distance = countDownDate - now;
  29.  
  30.   // Time calculations for days, hours, minutes and seconds
  31.   var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  32.   var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  33.   var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  34.   var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  35.  
  36.   // Display the result in the element with id="generated"
  37.   document.getElementById("generated").innerHTML = days + "d " + hours + "h "
  38.   + minutes + "m " + seconds + "s aikaa jäljellä!";
  39.  
  40.   // If the count down is finished, write some text
  41.   if (distance < 0) {
  42.    clearInterval(x);
  43.     //Aika täyttyi täytyy korvata viestillä, joka halutaan näyttää, kun laskuri on nollassa.
  44.    document.getElementById("generated").innerHTML = "Aika täyttyi!";  
  45.  
  46.  }
  47. }, 1000);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment