Skip to content

Instantly share code, notes, and snippets.

@jsdev
Created April 9, 2021 01:14
Show Gist options
  • Save jsdev/17d6e0abdc1ca1cdd8fdbb6a545a7d0b to your computer and use it in GitHub Desktop.
Save jsdev/17d6e0abdc1ca1cdd8fdbb6a545a7d0b to your computer and use it in GitHub Desktop.
formatDuration method
// constraints: video 24 hours or less
export default duration => {
const afterHours = duration % 3600;
const hours = Math.floor(duration / 3600);
const minutes = Math.floor(afterHours / 60);
const seconds = Math.ceil(afterHours % 60);
return [hours, minutes, seconds]
.filter(o => o)
.map(o => o > 9 ? o : '0' + o).join(':');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment