Skip to content

Instantly share code, notes, and snippets.

@Ref-Bit
Created September 26, 2021 14:31
Show Gist options
  • Save Ref-Bit/e97378f652a3088c93904f9b02a43aaa to your computer and use it in GitHub Desktop.
Save Ref-Bit/e97378f652a3088c93904f9b02a43aaa to your computer and use it in GitHub Desktop.
Convert time string format "hh:mm:ss" or "mm:ss" or "ss" to seconds
const convertHHMMSSToSeconds = timeStr => {
let p = timeStr.split(':'),
s = 0,
m = 1;
while (p.length > 0) {
s += m * parseInt(p.pop(), 10);
m *= 60;
}
return s;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment