Last active
December 22, 2015 05:38
-
-
Save Agneli/6425111 to your computer and use it in GitHub Desktop.
Function to convert time (type chronometer - 4:57:13) 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
function seconds(time) { | |
var split = time.split(':'); | |
if (split.length == 1) { | |
var seconds = split[0]; | |
//alert(seconds); | |
} else if (split.length == 2) { | |
var seconds = ((split[0] * 60) + parseInt(split[1])); | |
//alert(seconds); | |
} else if (split.length == 3) { | |
var seconds = ((((split[0] * 60) * 60) + parseInt(split[1] * 60)) + parseInt(split[2])); | |
//alert(seconds); | |
} | |
return(seconds); | |
} | |
//Call | |
seconds("3:25:57"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment