This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
JavaScript: Countdown Zähler zur in Sekunden
#1
Hallo,

ich habe einen Countdown Zähler auf der Seite.

Ich bin auf der suche, wie ich den Code ändern muss, damit er nicht anzeigt: Verbleibende Jahre, Tage, Stunden usw. Sondern, dass er nur die verbleibenden Sekunden anzeigt.
Sprich, es müsste doch eine Lösung gegeben, dass er die verbleibende Zeit (Jahre, Tage, Stunden, Minuten ...) komplett in Sekunden ausrechnet, die das als Countdown ablaufen.

Aktuell sieht er so aus:
https://count.filmbank.info/neu.html

Meine Vorstellung wäre: Die verbleibenden Sekunden bis zu Datum xy.


Der aktuelle Code sieht so aus:

<style>
/* CountDown */
#countdown {
text-align: center;
}
#countdown p {
display: inline-block;
padding: 10px;
background-color: #ff0000;
margin: 0 0 20px;
border-radius: 3px;
font-weight: bolder;
font-size: 40px;
color: black;
min-width: 3.6rem;
}
</style>

<script>
// CountDown
window.onload=function() {
// Month,Day,Year,Hour,Minute,Second
downTime('dec, 15, 2021, 22:00:00'); // *** Datum und Uhrzeit anpassen! ***
};

function downTime(countTo) {
nowd = new Date();
countTo = new Date(countTo);
difference = (countTo-nowd);
daysd=Math.floor(difference/(60*60*1000*24)*1);
yearsd = Math.floor(daysd / 365);
if (yearsd >= 1){ daysd = daysd - (yearsd * 365)}
hoursd=Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1);
minsd=Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
secsd=Math.floor((((difference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if (secsd < 0) {
yearsd = daysd = hoursd = minsd = 0;
secsd = -1;
window.clearTimeout(downTime);
// Eventuell eine Aktion ausführen ...
}
document.getElementById('yearsD').firstChild.nodeValue = yearsd;
document.getElementById('daysD').firstChild.nodeValue = daysd;
document.getElementById('hoursD').firstChild.nodeValue = hoursd;
document.getElementById('minutesD').firstChild.nodeValue = minsd;
document.getElementById('secondsD').firstChild.nodeValue = secsd;
if (secsd >= 0) {
clearTimeout(downTime.to);
downTime.to=setTimeout(function(){ downTime(countTo); },1000);
}
else {
document.getElementById('secondsD').firstChild.nodeValue = 0;
}
}
</script>

<div id="countdown">
<p id="yearsD">00</p>
<p>Jahre</p>
<p id="daysD">00</p>
<p>Tage</p>
<p id="hoursD">00</p>
<p>Stunden</p>
<p id="minutesD">00</p>
<p>Minuten</p>
<p id="secondsD">00</p>
<p>Sekunden</p>
</div>
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste