I'm trying to calculate the difference betweent two times, like 10:54 and 09:00 (expected difference is 1 hour 54 minutes):
Date.prototype.diffTime = function(date){
return new Date(this-date);
}
But this returns one hour more than I expect:
Thu Jan 01 1970 10:54:00 GMT+0100 (CET)
Thu Jan 01 1970 09:00:00 GMT+0100 (CET)
Thu Jan 01 1970 02:54:00 GMT+0100 (CET)
So why does it add one hour? The input times are correct. When I use getTime(), I get 1.9 hours (this-date/1000/60/60), which is also correct.
Thank you for your comments. I now wrote a simpler function which does what I need:
function getTimeHHMI(date){
var minutes = date/1000/60;
var hours = Math.floor(minutes/60);
minutes -= hours*60;
return [hours, minutes].join(':'); // returns 1:54
}