utilswxs.wxs
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var filter = {
// 分转元
Fen2Yuan: function (val) {
var result = val * 0.01; //分到元
// result += ''; //转成字符串
// result = result.toFixed(2); //留两位小数
return result.toFixed(2);
},
// 毫秒转格式
msTimeFormat: function (val, day = true) {
// var result = (val / 60 / 1000) + "分钟";
var t = val;
if (t <= 0) return "-";
var d = Math.floor(t / 1000 / 60 / 60 / 24);
var h = Math.floor(t / 1000 / 60 / 60 % 24) + (day ? 0 : 24 * d); // 含日的话,就不用24*d了
var m = Math.floor(t / 1000 / 60 % 60);
var s = Math.floor(t / 1000 % 60);
var zeroStr = "";
var dStr = d + "";
var hStr = h < 10 ? zeroStr + h : h;
var mStr = m < 10 ? zeroStr + m : m;
var sStr = s < 10 ? zeroStr + s : s;
var result = "";
if (d > 0 && day) {
result = dStr + "天" + hStr + "时" + mStr + "分" + sStr + "秒";
} else {
if (h > 0) {
result = hStr + "时" + mStr + "分" + sStr + "秒";
} else {
if (m > 0) {
result = mStr + "分" + sStr + "秒";
} else {
result = sStr + "秒";
}
}
}
return result;
}
}
module.exports = {
Fen2Yuan: filter.Fen2Yuan,
msTimeFormat: filter.msTimeFormat,
}