SHARE
TWEET

Untitled

a guest Jul 17th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export const toTime(sec) => {
  2.     let sec_num = parseInt(sec, 10);
  3.    
  4.     let hours   = Math.floor(sec_num / 3600);
  5.     let minutes = Math.floor((sec_num - (hours * 3600)) / 60);
  6.     let seconds = sec_num - (hours * 3600) - (minutes * 60);
  7.  
  8.     let hoursMem= hours;
  9.    
  10.     if (hours   < 10) {hours   = '0'+hours;}
  11.     if (minutes < 10) {minutes = '0'+minutes;}
  12.     if (seconds < 10) {seconds = '0'+seconds;}
  13.     let time    = `${minutes}:${seconds}`;
  14.     if (hoursMem > 0) {time = `${hours}:${time}`}
  15.     return time;
  16. }
  17.  
  18. // console.log(toTime(45));       // "00:45"
  19. // console.log(toTime(65));       // "01:05"
  20. // console.log(toTime(3590));     // "59:50"
  21. // console.log(toTime(7200));     // "02:00:00"
  22. // console.log(toTime(4117200));  // "1143:40:00"
RAW Paste Data
Top