How does one convert the following to seconds in JavaScript?
mm:ss.sss ?
What is the .sss?
How does one convert the following to seconds in JavaScript?
mm:ss.sss ?
What is the .sss?
".sss" is milliseconds
If you only want seconds, then simply extract the "ss" portion.
a quick tutorial an javascript Date: http://www.tizag.com/javascriptT/javascriptdate.php
Possibly you're asking about parsing that information, from user input? Would this be along the lines of what you need?
var input = '22:33.123';
var parts = /(\d\d):(\d\d.\d\d\d)/.exec(input);
function convert(parts) {
return parseInt(parts[1]) * 60 + parseFloat(parts[2]);
}
alert(input + ' is ' + convert(parts) + ' seconds');
You could do something like this:
function getSeconds(timestamp) {
var parts = timestamp.match(/\d+/g),
minute = 60,
hour = 60 * minute,
ms = 1/1000;
return (parts[0]*hour) + (parts[1]*minute) + (+parts[2]) + (parts[3]*ms);
}
getSeconds('01:33:33.235'); // 5613.235 seconds
Edited since you need the milliseconds.