forked from filecoin-project/starling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertDate.js
31 lines (24 loc) · 680 Bytes
/
convertDate.js
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
function convertDate(DATE) {
if (DATE === '00:00:00:00') {
return DATE;
}
let days, hours, minutes, seconds;
const date = new Date(DATE);
const dateNow = new Date();
const dateDiff = parseInt((dateNow - date) / 1000, 10);
days = format(parseInt(Math.floor(dateDiff / 86400), 10));
hours = format(parseInt(Math.floor(dateDiff / 3600) % 24, 10));
minutes = format(parseInt(Math.floor(dateDiff / 60) % 60, 10));
seconds = format(parseInt(dateDiff % 60, 10));
return `${days}:${hours}:${minutes}:${seconds}`;
}
function format(param) {
if (param < 10) {
return `0${param}`;
} else {
return param;
}
}
module.exports = {
convertDate
};