Last active
June 18, 2020 06:38
-
-
Save malikalichsan/2f52b8c52665df6297d8f26e5ee218ef to your computer and use it in GitHub Desktop.
Calculation between times in Javascript using moment.js
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
const calculationBetweenTimes = (startTime, endTime) => { | |
let diff = moment(endTime, 'HH:mm').diff(moment(startTime, 'HH:mm')) | |
let d = moment.duration(diff); | |
let hours = Math.floor(d.asHours()); | |
let minutes = moment.utc(diff).format("mm"); | |
return { | |
hours: hours, | |
minutes: minutes, | |
} | |
}; | |
let calculation = calculationBetweenTimes("15:00", "17:30"); | |
console.log(calculation); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment