毫秒转换 时 分 秒
formatSeconds: function (value) { //毫秒
var secondTime = parseInt(value / 1000);// 秒
var minuteTime = 0;// 分
var hourTime = 0;// 小时
if (secondTime > 60) {//如果秒数大于60,将秒数转换成整数
//获取分钟,除以60取整数,得到整数分钟
minuteTime = parseInt(secondTime / 60);
//获取秒数,秒数取佘,得到整数秒数
secondTime = parseInt(secondTime % 60);
//如果分钟大于60,将分钟转换成小时
if (minuteTime > 60) {
//获取小时,获取分钟除以60,得到整数小时
hourTime = parseInt(minuteTime / 60);
//获取小时后取佘的分,获取分钟除以60取佘的分
minuteTime = parseInt(minuteTime % 60);
}
}
var result = "" + parseInt(secondTime) + "秒";
if (minuteTime > 0) {
result = "" + parseInt(minuteTime) + "分" + result;
}
if (hourTime > 0) {
result = "" + parseInt(hourTime) + "小时" + result;
}
return result;
}
毫秒转换 00:00:00
getFormatTime: function (value) {
const str = value / 1000
//获取小时值
let timeH = "";
let H = parseInt(str / 3600);
if (H >= 0 && H < 1) {
timeH += "00:";
} else if (H >= 1 && H < 10) {
timeH += "0" + H + ":";
} else {
timeH += H + ":";
}
//获取分值
let timeM = "";
let M = parseInt(str / 60);
if (M === 0) {
timeM += "00:";
} else if (M > 0 && M < 10) {
timeM += "0" + M + ":";
} else {
timeM += M + ":";
}
var S = parseInt(str % 60);
var timeS = "";
if (S === 0) {
timeS += "00";
} else if (S > 0 && S < 10) {
timeS += "0" + S;
} else {
timeS += S;
}
return timeH + timeM + timeS;
}
网友评论