Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Odliczanie czasu
Mati-21
post
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 18.02.2006

Ostrzeżenie: (0%)
-----


Witam

Mam skrypt JS, który odlicza mi 1h.
  1. $time = time();
  2. $countdown = $time + 3600;
  3.  
  4. echo '<strong id="countdown_1"></strong>';
  5.  
  6. <script type="text/javascript">
  7. function countdown(targetDate, displayElement, onCountdownFinish) {
  8. if (!(targetDate && displayElement)) {
  9. return;
  10. }
  11. var formatTimeInterval = function(seconds) {
  12. var hrs = Math.floor(seconds / 3600)
  13. var min = Math.floor(seconds / 60) % 60;
  14. var sec = seconds % 60;
  15. return (hrs + ":" + min + ":" + sec).replace(/(^|:)(\d)(?=:|$)/g, "$10$2");
  16. };
  17. var refreshTimer = function() {
  18. var now = new Date();
  19. var diffMilliseconds = targetDate.getTime() - now.getTime();
  20. var diffSeconds = Math.round(diffMilliseconds / 1000);
  21. if (diffSeconds < 0) {
  22. diffSeconds = 0;
  23. }
  24. var countdownHTML = formatTimeInterval(diffSeconds)
  25. if (countdownHTML != displayElement.innerHTML) {
  26. displayElement.innerHTML = countdownHTML;
  27. }
  28. if (diffSeconds === 0) {
  29. clearInterval(intervalId);
  30. if (typeof onCountdownFinish === "function") {
  31. onCountdownFinish(targetDate);
  32. }
  33. }
  34. };
  35. var intervalId = setInterval(refreshTimer, 250);
  36. refreshTimer();
  37. }
  38.  
  39. (function() {
  40. var now = new Date();
  41. countdown(new Date(' . ($countdown) * 1000 . '), document.getElementById("countdown_1"));
  42. })();
  43. </script>';

Problem polega na tym, że nie zaczyna liczyć o 01:00:00.
Początkowo odliczał o 01:02:38 teraz od 01:03:51.
W ogóle nie znam się na pisaniu w JS dlatego zwracam się do Was czy możecie mi powiedzieć co jest źle w kodzie, że tak się dzieje?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 16.09.2025 - 08:49