this is my HTML code:
<ul class="countdown">
<li class="timer"><div id="days"></div><H1>Days</H1></li>
<li class="timer"><div id="hours"></div><H1>Hours</H1></li>
<li class="timer"><div id="mins"></div><H1>Minutes</H1></li>
<li class="timer"><div id="secs"></div><H1>Seconds</H1></li>
</ul>
And this is the JS code,
var xmas = new Date("jule 2, 2014 00:01:00");
var now = new Date();
var timeDiff = xmas.getTime() - now.getTime();
if (timeDiff <= 0) {
clearTimeout(timer);
document.write("Christmas is here!");
// Run any code needed for countdown completion here
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById("days").innerHTML = days;
document.getElementById("hours").innerHTML = hours;
document.getElementById("mins").innerHTML = minutes;
document.getElementById("secs").innerHTML = seconds;
var timer = setTimeout('cdtd()',1000);
The result is working in Chrome but IE and Firefox return NaN
.
I got it working.
Live example at: http://testnaman.neocities.org/quicktest2.html. This will not be permanent.
You need to change:
var xmas = new Date("jule 2, 2014 00:01:00");
To:
var xmas = new Date("July 2, 2014 00:01:00");
As it seems Firefox doesn't like incorrect spelling.
For more information take a look at: new Date() is working in Chrome but not Firefox.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments