get time difference in minutes in javascript

we created java-script function named “getTheDiffTime” using that function you will be able to fetch the time difference in various format.

javascript get time difference in minutes


function getTheDiffTime(dateone, datetwo,format){
//format = "Days", Hours, Minutes, Seconds
if(dateone > datetwo) {
var seconds = dateone.getTime() - datetwo.getTime();
} else {
var seconds = datetwo.getTime() - dateone.getTime();
}
var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;
if(format=="Days"){
var rformat = Math.floor(seconds / day);
seconds -= rformat * day;
//alert("days: "+rformat);
}else if(format=="Hours"){
// find the hours
rformat = translate(seconds / hour);
//alert("hours: "+rformat);
}else if (format=="Minutes"){
//find the mintues
rformat= translate(seconds / minute);
//alert("minutes: "+ rformat);
}else if(format=="Seconds"){
//find the seconds
rformat = translate(seconds / second);
//alert("seconds: "+rformat);
}

return rformat
//alert(rformat);

}

How to use this function here I am giving you the one good example.

I am going to get the current months minutes using this function.


//for calculating the current month in mintue -script
currentMonth = new Date();
plus_oneMonth = new Date();
plus_oneMonth.setMonth(plus_oneMonth.getMonth()+1);

getTheDiffTime(plus_oneMonth,currentMonth,"Minutes");

You will get return the minutes.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.