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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.