I have a function in JavaScript to get the difference between two times:
function get_time_difference(laterDate) {
var earlierDate = new Date();//Now
var nTotalDiff = laterDate.getTime() - earlierDate.getTime();
var oDiff = new Object();
oDiff.days = Math.floor(nTotalDiff / 1000 / 60 / 60 / 24);
nTotalDiff -= oDiff.days * 1000 * 60 * 60 * 24;
oDiff.hours = Math.floor(nTotalDiff / 1000 / 60 / 60);
nTotalDiff -= oDiff.hours * 1000 * 60 * 60;
oDiff.minutes = Math.floor(nTotalDiff / 1000 / 60);
nTotalDiff -= oDiff.minutes * 1000 * 60;
oDiff.seconds = Math.floor(nTotalDiff / 1000);
if (0 == oDiff.minutes && 0 == oDiff.hours) {
//Do Something
}
return oDiff.minutes;
}
When times are equal I need to run a particular function,
my problem is that sometimes he returns 59 minutes, while it should return 0 ..
Why is this happening? How can I fix this?
I fix it this way: