16. juli 2003 - 22:51Der er
5 kommentarer og 1 løsning
tæller tid ned til 31 august
Jeg kunne godt tænke mig at tælle dage, timer, minutter og sekunder til 31 august kl. 14.30.00 men får det kun til at virke med hele dage
onClipEvent(enterFrame) { tid = new Date(); dato = tid.getDate(); d = 31 - dato; t = 23 - tid.getHours(); m = 59 - tid.getMinutes(); s = 59 - tid.getSeconds(); _root.strDato = ("Der er " + d + " dage " + t+" timer "+m+" minutter og "+s+" sekunder\ntilbage til 31 august kl. 14.30"); }
Fin kode men der er fejl i udregningen af dage. Det ser ud som om at timer, minutter, sek er ok men hvad er der glat med dagende?
koden: // Set the destination day for December 31, 2003 @ 11:59 myDate = new Date(2003, 11, 31, 23, 59, 59); setInterval(traceCountdown, 1000, myDate);
function traceCountdown(destDate) { c = getCountDown(destDate);
// Format each element to pad for numbers < 10 c.days = (c.days < 10) ? "0" + c.days : c.days; c.hours = (c.hours < 10) ? "0" + c.hours : c.hours; c.minutes = (c.minutes < 10) ? "0" + c.minutes : c.minutes; c.seconds = (c.seconds < 10) ? "0" + c.seconds : c.seconds;
function getCountDown(destDate) { // Get the difference between the dates diff = destDate - (new Date());
// Extract seconds, minutes, hours, and days s = Math.floor(diff /= 1000); m = Math.floor(diff /= 60); h = Math.floor(diff /= 60); d = Math.floor(diff /= 24);
// Limit seconds, minutes, and hours to appropriate ranges s %= 60; m %= 60; h %= 24;
currentDate = new Date(); // note: flash starts to count months from 0, so January is month 0 and December month 11. // the date here is expressed as follows: Year, Month, Day, Hour, Minutes, Seconds. endDate = new Date(2003, 6, 18, 12, 59, 59); days = (endDate-currentDate)/1000/60/60/24; daysRound = Math.floor(days); hours = (endDate-currentDate)/1000/60/60-(24*daysRound); hoursRound = Math.floor(hours); minutes = (endDate-currentDate)/1000/60-(24*60*daysRound)-(60*hoursRound); minutesRound = Math.floor(minutes); seconds = (endDate-currentDate)/1000-(24*60*60*daysRound)-(60*60*hoursRound)-(60*minutesRound); secondsRound = Math.round(seconds); // Check when to put day and when to put days if (daysRound == 1) { dy = " day "; } else { dy = " days "; } if (secondsRound == 60) { secondsRound = 0; } if (minutesRound == 60) { minutesRound = 0; } if (secondsRound<=9) { secondsRound = "0"+secondsRound; } if (minutesRound<=9) { minutesRound = "0"+minutesRound; } if (daysRound<=-1) { timeRemaining = "Jaaa"; } else { timeRemaining = daysRound+dy+hoursRound+":"+minutesRound+":"+secondsRound; }
Takker jeg bruger onkelmor's link til koden derfor får kan point.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.