Advertisement
pegasusthemes

comet // javascript

Apr 14th, 2019
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <script>
  2. var curday;
  3. var secTime;
  4. var ticker;
  5.  
  6. function getSeconds() {
  7. var nowDate = new Date();
  8. var dy = 1 ; // CHANGE DAY: Sunday through Saturday, 0 to 6
  9. var countertime = new Date(Date.UTC(nowDate.getUTCFullYear(),nowDate.getUTCMonth(), nowDate.getUTCDate(), 1, 0, 0)); // CHANGE TIME: change 1 to the time you need, 24 hours system, use utc time zone
  10.  
  11. var curtime = nowDate.getTime();
  12. var atime = countertime.getTime();
  13. var diff = parseInt((atime - curtime)/1000);
  14. if (diff > 0) { curday = dy - nowDate.getDay() }
  15. else { curday = dy - nowDate.getDay() -1 }
  16. if (curday < 0) { curday += 7; }
  17. if (diff <= 0) { diff += (86400 * 7) }
  18. startTimer (diff);
  19. }
  20.  
  21. function startTimer(secs) {
  22. secTime = parseInt(secs);
  23. ticker = setInterval("tick()",1000);
  24. tick();
  25. }
  26.  
  27. function tick() {
  28. var secs = secTime;
  29. if (secs>0) {
  30. secTime--;
  31. }
  32. else {
  33. clearInterval(ticker);
  34. getSeconds();
  35. }
  36.  
  37. var days = Math.floor(secs/86400);
  38. secs %= 86400;
  39. var hours= Math.floor(secs/3600);
  40. secs %= 3600;
  41. var mins = Math.floor(secs/60);
  42. secs %= 60;
  43.  
  44. document.getElementById("days").innerHTML = curday;
  45. document.getElementById("hours").innerHTML = ((hours < 10 ) ? "0" : "" ) + hours;
  46. document.getElementById("minutes").innerHTML = ( (mins < 10) ? "0" : "" ) + mins;
  47. document.getElementById("seconds").innerHTML = ( (secs < 10) ? "0" : "" ) + secs;
  48. }
  49. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement