I am trying to compare the time now and a time in a future date. When these times are the same I want to show a message. However, the code below is not working. I have been checking the console and now.getTime()
is never the same as end.getTime()
, presumably as they are in ms?
Does anyone know how to overcome this? Following this answer here I believe it should work.
function compareTimes() {
var end = new Date("August 31, 2016 11:04:18");
var now = new Date();
if (now.getTime() == end.getTime()) {
clearInterval(timer);
document.getElementById('countup').innerHTML = 'EXPIRED!';
return;
}
}
setInterval(compareTimes, 1000);