Created
August 5, 2022 06:49
-
-
Save Shaxadhere/a5434ea0beb09f99e0f66c65a329378d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 calcMinutes = (time="12:30 AM-07:30 PM") => { | |
const _time = time.split("-") | |
const lastMeridian = _time[1].slice(-2) | |
let firstDate = "2022-01-01" | |
let lastDate = "2022-01-01" | |
if(lastMeridian=="AM"){ | |
firstDate = "2022-01-02" | |
} | |
const ageDifMs = new Date(firstDate+' '+_time[1]).getTime() - new Date(lastDate+' '+_time[0]).getTime(); | |
const ageDate = new Date(ageDifMs); | |
const age = Math.abs(ageDate.getUTCFullYear() - 1970); | |
console.log(ageDifMs/60000) | |
} | |
calcMinutes() | |
// console.log((ageDifMs/3600)/3600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment