-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.js
48 lines (42 loc) · 1.1 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
37
38
39
40
41
42
43
44
45
46
47
48
const getDate = (date = new Date()) => {
const currentDate = date;
const year = currentDate.getFullYear();
const day = currentDate.getDate();
const month = currentDate.getMonth() + 1;
const currentDateObj = {
year,
day,
month
};
return currentDateObj;
};
const getTime = (time = new Date()) => {
const currentTime = time;
const hours = currentTime.getHours();
const minutes = currentTime.getMinutes();
const seconds = currentTime.getSeconds();
const currentTimeObj = {
hours,
minutes,
seconds
};
return currentTimeObj;
};
const getDateFormat = date => {
const { year, month, day } = date;
return `${year}-${month < 10 ? `0${month}` : month}-${
day < 10 ? `0${day}` : day
}`;
};
const getTimeFormat = (time, options) => {
const { hours, minutes, seconds } = time;
if (options === "clock") {
return `${hours < 10 ? `0${hours}` : hours}:${
minutes < 10 ? `0${minutes}` : minutes
}:${seconds < 10 ? `0${seconds}` : seconds}`;
} else {
return `${hours < 10 ? `0${hours}` : hours}:${
minutes < 10 ? `0${minutes}` : minutes
}`;
}
};