Skip to content

Instantly share code, notes, and snippets.

@Agneli
Last active December 22, 2015 05:38
Show Gist options
  • Save Agneli/6425111 to your computer and use it in GitHub Desktop.
Save Agneli/6425111 to your computer and use it in GitHub Desktop.
Function to convert time (type chronometer - 4:57:13) to seconds.
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