js 毫秒换算成秒

时间:2024-04-16 06:13:20
$scope.formatSeconds = function (value) {
var reg = /^(-|\+)?\d+$/;
if (reg.test(value)) {
var hour = Math.floor(value / 3600);
var minute = Math.floor((value % 3600) / 60);
var second = value % 60;
var posstr = "";
if (hour) {
if (hour < 10)
posstr += "0";
posstr += hour;
posstr += ":";
} else {
posstr += "00:";
}
if (minute < 10)
posstr += "0";
posstr += minute;
posstr += ":";
if (second < 10)
posstr += "0";
posstr += second;
return posstr;
} else {
return "";
}
};