Need to get the minutes elapsed since midnight? Here’s how to do it in JavaScript.
get-minutes-elapsed-since-midnight.ts
exportfunctiongetMinutesElapsedSinceMidnight(){// Get the current dateconst currentDate =newDate();// Create a date from that, but 0 out the hours, minutes, seconds, and milliseconds (aka midnight)const currentDateAsMidnight =newDate( currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(),);// Get the milliseconds elapsed since midnightconst msElapsedSinceMidnight = currentDate.getTime()- currentDateAsMidnight.getTime();// Convert the milliseconds to minutesconst minutesElapsedSinceMidnight = Math.floor( msElapsedSinceMidnight /1000/60,);return minutesElapsedSinceMidnight;}