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(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.

About Me: Paul Kinlan

I lead the Chrome Developer Relations team at Google.

We want people to have the best experience possible on the web without having to install a native app or produce content in a walled garden.

Our team tries to make it easier for developers to build on the web by supporting every Chrome release, creating great content to support developers on web.dev, contributing to MDN, helping to improve browser compatibility, and some of the best developer tools like Lighthouse, Workbox, Squoosh to name just a few.