You can get the current time stamp, set the clock to 24,
and subtract the old mark from the new.
function beforeMidnight(){ var mid= new Date(), ts= mid.getTime(); mid.setHours(24, 0, 0, 0); return Math.floor((mid - ts)/60000); }
alert (beforeMidnight () + 'minutes to midnight ")
source share