提交 | 用户 | 时间
|
820397
|
1 |
/** |
H |
2 |
* Independent time operation tool to facilitate subsequent switch to dayjs |
|
3 |
*/ |
|
4 |
// TODO 芋艿:【锁屏】可能后面删除掉 |
|
5 |
import dayjs from 'dayjs' |
|
6 |
|
|
7 |
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss' |
|
8 |
const DATE_FORMAT = 'YYYY-MM-DD' |
9c91ad
|
9 |
const DATE_TIME_PATTERN_STRING = 'YYYYMMDDHHmmss' |
820397
|
10 |
|
H |
11 |
export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string { |
|
12 |
return dayjs(date).format(format) |
|
13 |
} |
|
14 |
|
|
15 |
export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string { |
|
16 |
return dayjs(date).format(format) |
|
17 |
} |
|
18 |
|
9c91ad
|
19 |
export function formatToDateString(date?: dayjs.ConfigType, format = DATE_TIME_PATTERN_STRING): string { |
D |
20 |
return dayjs(date).format(format) |
|
21 |
} |
|
22 |
|
820397
|
23 |
export const dateUtil = dayjs |
d7fad0
|
24 |
|
J |
25 |
export function getYMDHMS (timestamp: number | string | Date) { |
|
26 |
const time = new Date(timestamp) |
|
27 |
const year = time.getFullYear() |
|
28 |
let month = time.getMonth() + 1 + '' |
|
29 |
let date = time.getDate() + '' |
|
30 |
let hours = time.getHours() + '' |
|
31 |
let minute = time.getMinutes() + '' |
|
32 |
let second = time.getSeconds() + '' |
|
33 |
|
|
34 |
if (month < 10) { month = '0' + month } |
|
35 |
if (date < 10) { date = '0' + date } |
|
36 |
if (hours < 10) { hours = '0' + hours } |
|
37 |
if (minute < 10) { minute = '0' + minute } |
|
38 |
if (second < 10) { second = '0' + second } |
|
39 |
return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second |
|
40 |
} |
0d21bc
|
41 |
export function getYMDHM0 (timestamp: number | string | Date) { |
D |
42 |
const time = new Date(timestamp) |
|
43 |
const year = time.getFullYear() |
|
44 |
let month = time.getMonth() + 1 + '' |
|
45 |
let date = time.getDate() + '' |
|
46 |
let hours = time.getHours() + '' |
|
47 |
let minute = time.getMinutes() + '' |
|
48 |
|
|
49 |
if (month < 10) { month = '0' + month } |
|
50 |
if (date < 10) { date = '0' + date } |
|
51 |
if (hours < 10) { hours = '0' + hours } |
|
52 |
if (minute < 10) { minute = '0' + minute } |
|
53 |
return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + '00' |
|
54 |
} |