判断输入时间显示不同结构

最近在用vue做公司的后台运营系统,遇到了一个js的根据时间去处理内容显示不同的结果;代码如下

handleDateStr(strDate){//显示时间(d)
var resStr = '';
if (strDate < 60 * 1000 && strDate >= 0) {
resStr = "(" + parseInt(strDate / 1000) + "s)";
}else if (strDate >= 60 * 1000 && strDate < 60 * 60 * 1000) {
resStr = "(" + parseInt(strDate / (1000 * 60)) + "m)";
}else if (strDate >= 60 * 1000 * 60 && strDate < 60 * 60 * 1000 * 24) {
resStr = "(" + parseInt(strDate / (1000 * 60 * 60)) + "h"+ parseInt((strDate % (60 * 60 * 1000)) / (1000 * 60)) +"m)"
}else{
resStr = "(" + parseInt(strDate / (1000 * 60 *60 *24)) + "d)"
}
return resStr;
}

可意为输入一个时间strDate,运行函数后代码会根据输入的时间返回不同的结果 并做了取整处理

原文地址:https://www.cnblogs.com/sunweinan/p/timer.html