Skip to content

Instantly share code, notes, and snippets.

@Shaxadhere
Created August 5, 2022 06:49
Show Gist options
  • Save Shaxadhere/a5434ea0beb09f99e0f66c65a329378d to your computer and use it in GitHub Desktop.
Save Shaxadhere/a5434ea0beb09f99e0f66c65a329378d to your computer and use it in GitHub Desktop.
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