How to get the number of seconds between 2 dates in JavaScript

1 Answer

0 votes
function getSecondsBetween2Dates(startDate, endDate) {
  	const millisecondsInSecond = 1000;

  	return Math.round(Math.abs(endDate - startDate) / millisecondsInSecond);
}

console.log(getSecondsBetween2Dates(new Date(2022, 4, 08, 8, 03, 0), new Date(2022, 4, 08, 8, 04, 35)));

  
  
  
  
/*
run:
  
95
  
*/

 



answered Apr 8, 2022 by avibootz

Related questions

1 answer 135 views
1 answer 125 views
1 answer 101 views
1 answer 121 views
1 answer 97 views
...