Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. function timeLeftTodayAsClock() {
  2. //let totalMillisecondsInADay = (new Date('Jan 01 1970 23:59:59:999 GMT+0000')).getTime() + 1; // the one just flips the 999 to 0000
  3. const totalMillisecondsInADay = 86400000; // number of ms in a day
  4. return (new Date(totalMillisecondsInADay - Date.now())).toString().match(/\d\d:\d\d:\d\d/)[0];
  5. }
  6.  
  7. console.log(timeLeftTodayAsClock());
  8.  
  9. //output looks like 12:23:38
  10. //NB: Works for one day, e.g on a deal/auction website
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement