Skip to content

Instantly share code, notes, and snippets.

@samuelbeek
Created February 2, 2015 15:56
Show Gist options
  • Save samuelbeek/178774a5a01ff87a4b2c to your computer and use it in GitHub Desktop.
Save samuelbeek/178774a5a01ff87a4b2c to your computer and use it in GitHub Desktop.
Convert to time in seconds (javascript)
var convertToSeconds = function(time) {
if(!isNaN(time)){
return time
}
var timeArray = time.split(':'),
seconds = 0, minutes = 1;
while (timeArray.length > 0) {
seconds += minutes * parseInt(timeArray.pop(), 10);
minutes *= 60;
}
return seconds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment