I have the following date string: 2020-04-21T15:28:26.000Z
I would like to convert it into the amount of hours and minutes that have passed since that.
For example: 5:10
I have the following date string: 2020-04-21T15:28:26.000Z
I would like to convert it into the amount of hours and minutes that have passed since that.
For example: 5:10
function getPassedTime(dateStr){
const date = new Date(dateStr);
const now = new Date();
var diff = now.getTime() - date.getTime();
var diffInMinutes = Math.round(diff / 60000);
var hours = (diffInMinutes / 60);
var passeHours = Math.floor(hours);
var minutes = (hours - passeHours) * 60;
var passedMinutes = Math.round(minutes);
return passeHours+":"+passedMinutes;
}
console.log(getPassedTime('2020-04-21T15:28:26.000Z'))
function getDiffTime(time) {
const old = new Date(time)
const now = new Date();
const diff = now - old;
const msInHrs = 1000 * 60 * 60;
const msInMn = 1000 * 60;
const hrs = Math.floor(diff / msInHrs);
const mn = Math.floor((diff % (hrs * msInHrs)) / msInMn);
return `${hrs}:${mn}`;
}
console.log(getDiffTime('2020-04-21T15:28:26.000Z'));