Reputation:
I am trying to get the exact amount of seconds, minutes etc. left to a specific date. This may sound stupid but why is the result doubled? That doesn't seem right, does it?
setInterval(function() {
var startDate = new Date(),
startDateTime = startDate.getTime(),
endDate = new Date(2012, 5, 14),
endDateTime = endDate.getTime();
var timeLeft = endDateTime - startDateTime;
var seconds = Math.round(timeLeft / 1000),
minutes = Math.round(seconds / 60),
hours = Math.round(minutes / 60),
days = Math.round(hours / 24),
weeks = Math.round(days / 7);
console.log(weeks, days, hours, minutes, seconds);
}, 1000);
Upvotes: 0
Views: 92
Reputation: 6947
The JavaScript Date constructor works just like the Java one--- Days and Years are 1-based, but the month is zero-based. So the date February 10th, 2015 is:
var aDate= new Date(2015,1,10);
Upvotes: 4