Created
February 2, 2015 15:56
-
-
Save samuelbeek/178774a5a01ff87a4b2c to your computer and use it in GitHub Desktop.
Convert to time in seconds (javascript)
This file contains 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
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