helper.wxs
1.04 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
47
48
49
50
51
52
function getDateList(date) {
if (!date) {
return []
}
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
return [year, month, day];
}
function formatN(format, num) {
var n = num + '';
var nList = n.split('')
var l = nList.length;
var fl = format.length;
if (format.length < nList.length) {
return nList;
}
var el = fl - l;
for(var i = 0; i < el; i++) {
nList.splice(0, 0, '0');
}
return nList.join('');
}
function formatTime(start, end) {
var startTime = getDate(start * 1000);
var endTime = getDate(end * 1000);
var startDate = getDateList(startTime);
var endDate = getDateList(endTime);
var startDateFormat = startDate[0] + '.' + formatN('00', startDate[1]) + '.' + formatN('00', startDate[2])
var endDateFormat = '-' + formatN('00', endDate[1]) + '.' + formatN('00', endDate[2]);
if (!end) {
return "即将上线:" + startDateFormat;
}
return startDateFormat + endDateFormat;
}
module.exports = {
formatTime: formatTime,
formatN: formatN,
};