-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdate.js
36 lines (31 loc) · 1.02 KB
/
date.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
32
33
34
35
36
module.exports = {
timeFmtDb: (e) => {
let epoch = e
if (epoch.length === 10) epoch = e * 1000
const date = new Date(epoch) // this unfortunately uses the local time
let minutes = date.getMinutes();
if (minutes < 10) minutes = '0' + String(minutes);
let seconds = date.getSeconds();
if (seconds < 10) seconds = '0' + String(seconds);
let hours = date.getHours();
let day = date.getDate()
if (day < 10) day = '0' + String(day);
if (hours < 10) hours = '0' + String(hours);
let month = date.getMonth() + 1;
if (month < 10) month = '0' + month;
return (Number(date.getFullYear())) + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
},
_timeFmtDb: (e) => {
return module.exports.timeFmtDb(e).replace(/ /g, '_')
},
_toEpoch: (_timeFmt) => {
const time = _timeFmt.replace(/_/g, ' ')
return module.exports.epochFromDate(time)
},
epochFromDate: (date) => {
return new Date(date).getTime()
},
dateNowBKK: () => {
return Date.now()
}
}