-
Notifications
You must be signed in to change notification settings - Fork 0
/
timespamp.ts
44 lines (37 loc) · 933 Bytes
/
timespamp.ts
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
function year(now: Date) {
return now.getFullYear()
}
function month(now: Date) {
return zeroPad(now.getMonth() + 1)
}
function date(now: Date) {
return zeroPad(now.getDate())
}
function hour(now: Date) {
return zeroPad(now.getHours())
}
function minute(now: Date) {
return zeroPad(now.getMinutes())
}
function second(now: Date) {
return zeroPad(now.getSeconds())
}
function zeroPad(num: number) {
if (num.toString().length === 1) {
return "0" + num
} else {
return num.toString()
}
}
export function getTimeStamp() {
const now = new Date
return `${year(now)}_${month(now)}_${date(now)}-${hour(now)}_${minute(now)}_${second(now)}`
}
export function getDate() {
const now = new Date
return `${year(now)}-${month(now)}-${date(now)}`
}
export function getDateHour() {
const now = new Date
return `${year(now)}-${month(now)}-${date(now)}-${hour(now)}`
}