I want to find difference between two dates. I have tried this code but it gives me wrong values. I want get total minutes between two dates, so I am converting hours to minutes and adding to minutes.
var hourDiff = timeEnd - timeStart;
var diffHrs = Math.round((hourDiff % 86400000) / 3600000);
var diffMins = Math.round(((hourDiff % 86400000) % 3600000) / 60000);
diffMins = diffMins + (diffHrs * 60);
Here timeEnd
is Mon Jan 01 2007 11:30:00 GMT+0530 (India Standard Time)
,
and timeStart
is Mon Jan 01 2007 11:00:00 GMT+0530 (India Standard Time)
.
Here if hours difference I am getting 1
, it should be 0
and minutes I am getting 30
that is right. But hours should be 0
. Am I doing something wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…