Last active
September 11, 2022 01:40
-
-
Save MBlore/08d4556ac81b4a254d80aac344065e32 to your computer and use it in GitHub Desktop.
JS Time difference between two dates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the amount of seconds between two given dates. | |
* @param {Date} dtStart The start time. | |
* @param {Date} dtEnd The end time. | |
* @returns The number of seconds between the two dates. | |
*/ | |
function secondsBetween(dtStart, dtEnd) { | |
var diff = (dtStart.getTime() - dtEnd.getTime()) / 1000; | |
return Math.abs(diff); | |
} | |
/** | |
* Returns the amount of minutes between two given dates. | |
* @param {Date} dtStart The start time. | |
* @param {Date} dtEnd The end time. | |
* @returns The number of minutes between the two dates. | |
*/ | |
function minutesBetween(dtStart, dtEnd) { | |
var diff = (dtStart.getTime() - dtEnd.getTime()) / 1000; | |
diff /= 60; | |
return Math.abs(diff); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment