复制即用
百度有一个毫秒换算器,可以用它来验证代码换算的正确与否。
console.log(Tools(9252206000)) //三月
// 毫秒数转为天,小时分钟秒
function Tools (time) {
let daysRound = Math.floor(time / 1000 / 60 / 60 / 24);
let minutesRound = Math.floor(time / 1000 / 60 - (24 * 60 * daysRound));
let month = Math.floor(daysRound / 30)
let weekend = Math.floor(daysRound / 7)
let result = null
if (daysRound >= 1) {
if (daysRound <= 365) {
if (month === 0) {
if (weekend >= 1) {
result = "" + weekend + "周";
} else {
result = "" + daysRound + "天";
}
} else {
result = "" + month + "月";
}
} else {
result = "" + Math.floor(daysRound / 365) + "年";
}
} else if (minutesRound >= 1) {
console.log(99,minutesRound)
if (minutesRound >= 60) {
result = "" + Math.floor(minutesRound / 60) + "小时";
} else {
result = "" + minutesRound + "分钟";
}
} else {
result = "刚刚";
}
return result;
}