Created
September 26, 2021 14:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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