-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconvertTime.js
More file actions
20 lines (17 loc) · 837 Bytes
/
convertTime.js
File metadata and controls
20 lines (17 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export default (seconds, timeFormats) => {
if (Number.isNaN(seconds)) {
return '';
}
const myTime = new Date(seconds * 1000);
const hour = myTime.getUTCHours();
const min = timeFormats.showHour ? myTime.getUTCMinutes() : myTime.getUTCMinutes() + (hour * 60);
const sec = timeFormats.showMin ? myTime.getUTCSeconds() : myTime.getUTCSeconds() + (min * 60);
const strHour = (timeFormats.padHour && hour < 10) ? `0${hour}` : hour;
const strMin = (timeFormats.padMin && min < 10) ? `0${min}` : min;
const strSec = (timeFormats.padSec && sec < 10) ? `0${sec}` : sec;
let strTime = '';
strTime += timeFormats.showHour ? strHour + timeFormats.sepHour : '';
strTime += timeFormats.showMin ? strMin + timeFormats.sepMin : '';
strTime += timeFormats.showSec ? strSec + timeFormats.sepSec : '';
return strTime;
};