Seconds to HH:MM:SS.MS format

This is mostly for future reference. I recently built a tool trims a video and I
needed to convert from seconds to the time-code format that FFMPEG uses of
hh:mm:ss.ms
const secondsToTimeCode = function(timeInSeconds) {

const zeropad = function(num…


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

This is mostly for future reference. I recently built a tool trims a video and I needed to convert from seconds to the time-code format that FFMPEG uses of hh:mm:ss.ms

const secondsToTimeCode = function(timeInSeconds) {

  const zeropad = function(number) {
      return (number <= 9) ? `0{$number}`: number;
  }

  const hours = Math.floor(timeInSeconds / 3600)
  const minutes = Math.floor((timeInSeconds - (hours * 3600)) / 60) % 60;
  const seconds = timeInSeconds % 60;

  return `${zeropad(hours)}:${zeropad(minutes)}:${zeropad(seconds)}`;
};

It worked well for what I needed.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2016-12-17T12:20:31+00:00) Seconds to HH:MM:SS.MS format. Retrieved from https://www.scien.cx/2016/12/17/seconds-to-hhmmss-ms-format/

MLA
" » Seconds to HH:MM:SS.MS format." Paul Kinlan | Sciencx - Saturday December 17, 2016, https://www.scien.cx/2016/12/17/seconds-to-hhmmss-ms-format/
HARVARD
Paul Kinlan | Sciencx Saturday December 17, 2016 » Seconds to HH:MM:SS.MS format., viewed ,<https://www.scien.cx/2016/12/17/seconds-to-hhmmss-ms-format/>
VANCOUVER
Paul Kinlan | Sciencx - » Seconds to HH:MM:SS.MS format. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2016/12/17/seconds-to-hhmmss-ms-format/
CHICAGO
" » Seconds to HH:MM:SS.MS format." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2016/12/17/seconds-to-hhmmss-ms-format/
IEEE
" » Seconds to HH:MM:SS.MS format." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2016/12/17/seconds-to-hhmmss-ms-format/. [Accessed: ]
rf:citation
» Seconds to HH:MM:SS.MS format | Paul Kinlan | Sciencx | https://www.scien.cx/2016/12/17/seconds-to-hhmmss-ms-format/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.