time convert in javascript
How does one convert the 开发者_JAVA技巧following to seconds in JavaScript?
mm:ss.sss ?
What is the .sss?
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.
".sss" is milliseconds
If you only want seconds, then simply extract the "ss" portion.
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');
a quick tutorial an javascript Date: http://www.tizag.com/javascriptT/javascriptdate.php
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
精彩评论