While this code works fine in Chrome, I am encountering issues with IE and Firefox as it returns NaN. Any insights or assistance would be greatly appreciated.
Essentially, this code is intended to be a simple countdown function for days. If there are errors in my implementation, please feel free to point them out.
var start_date = "09 Sep 16";
var end = new Date(start_date); // set expiry date and time..
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour *24
var timer;
function showRemaining()
{
var now = new Date();
var distance = end - now;
if (distance < 0 ) {
// handle expiry here..
clearInterval( timer ); // stop the timer from continuing ..
alert('Expired'); // alert a message that the timer has expired..
return; // break out of the function so that we do not update the counters with negative values..
}
var days = Math.floor(distance / _day);
document.getElementById('date').innerHTML = ' ' + days + ' ';
}
timer = setInterval(showRemaining, 1000);
Count down: <div id="date"></div>