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 min
If you are confident that the difference will be less that 24 hours, the following works.
var timeStart= new Date('2015-01-01 03:45:45.890');
var timeEnd = new Date('2015-01-01 05:12:34.567');
var timeDiff = new Date(timeEnd.getTime() - timeStart.getTime());
var humanTime = timeDiff.toISOString().substring(11, 23);
var diffHours = timeDiff.toISOString().substring(11, 12);
humanTime is 01:26:48.677, diffHours is 01
You can get Time difference in hours minutes and secons like countdown by using following:
var diff = EndedTime - StartedTime;
var hours = Math.floor(diff / 3.6e6);
var minutes = Math.floor((diff % 3.6e6) / 6e4);
var seconds = Math.floor((diff % 6e4) / 1000);
var duration = hours+":"+minutes+":"+seconds;
Hope This Help. Thanks