Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Created January 18, 2017 16:49
Show Gist options
  • Select an option

  • Save X-Raym/53b5e6ca55744265045bd8f846ea1ce7 to your computer and use it in GitHub Desktop.

Select an option

Save X-Raym/53b5e6ca55744265045bd8f846ea1ce7 to your computer and use it in GitHub Desktop.
Parse TimeCode to Seconds
var string = "40:01.456";
var time_array = string.split(':');
time_array = time_array.reverse();
console.log( time_array );
console.log( 'length', time_array.length );
var multiply = [1, 60, 3600];
var seconds = 0;
for( i=0; i < time_array.length; i++) {
console.log( time_array[i] + '*' + multiply[i] + '+' + seconds )
seconds = time_array[i] * multiply[i] + seconds;
}
console.log( seconds );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment