Witam
Mam skrypt JS, który odlicza mi 1h.
$countdown = $time + 3600;
echo '<strong id="countdown_1"></strong>';
<script type="text/javascript">
function countdown(targetDate, displayElement, onCountdownFinish) {
if (!(targetDate && displayElement)) {
return;
}
var formatTimeInterval = function(seconds) {
var hrs = Math.floor(seconds / 3600)
var min = Math.floor(seconds / 60) % 60;
var sec = seconds % 60;
return (hrs + ":" + min + ":" + sec).replace(/(^|:)(\d)(?=:|$)/g, "$10$2");
};
var refreshTimer = function() {
var now = new Date();
var diffMilliseconds = targetDate.getTime() - now.getTime();
var diffSeconds = Math.round(diffMilliseconds / 1000);
if (diffSeconds < 0) {
diffSeconds = 0;
}
var countdownHTML = formatTimeInterval(diffSeconds)
if (countdownHTML != displayElement.innerHTML) {
displayElement.innerHTML = countdownHTML;
}
if (diffSeconds === 0) {
clearInterval(intervalId);
if (typeof onCountdownFinish === "function") {
onCountdownFinish(targetDate);
}
}
};
var intervalId = setInterval(refreshTimer, 250);
refreshTimer();
}
(function() {
var now = new Date();
countdown(new Date(' . ($countdown) * 1000 . '), document.getElementById("countdown_1"));
})();
</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?