提交 | 用户 | 时间
|
82c159
|
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' |
|
9 |
|
|
10 |
export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string { |
|
11 |
return dayjs(date).format(format) |
|
12 |
} |
|
13 |
|
|
14 |
export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string { |
|
15 |
return dayjs(date).format(format) |
|
16 |
} |
|
17 |
|
|
18 |
export const dateUtil = dayjs |
5cc1d9
|
19 |
export function getYMDHMS (timestamp: number | string | Date) { |
D |
20 |
const time = new Date(timestamp) |
|
21 |
const year = time.getFullYear() |
|
22 |
let month = time.getMonth() + 1 + '' |
|
23 |
let date = time.getDate() + '' |
|
24 |
let hours = time.getHours() + '' |
|
25 |
let minute = time.getMinutes() + '' |
|
26 |
let second = time.getSeconds() + '' |
|
27 |
|
|
28 |
if (month < 10) { month = '0' + month } |
|
29 |
if (date < 10) { date = '0' + date } |
|
30 |
if (hours < 10) { hours = '0' + hours } |
|
31 |
if (minute < 10) { minute = '0' + minute } |
|
32 |
if (second < 10) { second = '0' + second } |
|
33 |
return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second |
|
34 |
} |
|
35 |
export function getYMDHM0 (timestamp: number | string | Date) { |
|
36 |
const time = new Date(timestamp) |
|
37 |
const year = time.getFullYear() |
|
38 |
let month = time.getMonth() + 1 + '' |
|
39 |
let date = time.getDate() + '' |
|
40 |
let hours = time.getHours() + '' |
|
41 |
let minute = time.getMinutes() + '' |
|
42 |
|
|
43 |
if (month < 10) { month = '0' + month } |
|
44 |
if (date < 10) { date = '0' + date } |
|
45 |
if (hours < 10) { hours = '0' + hours } |
|
46 |
if (minute < 10) { minute = '0' + minute } |
|
47 |
return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + '00' |
|
48 |
} |
|
49 |
export function getYMD (timestamp: number | string | Date) { |
|
50 |
const time = new Date(timestamp) |
|
51 |
const year = time.getFullYear() |
|
52 |
let month = time.getMonth() + 1 + '' |
|
53 |
let date = time.getDate() + '' |
|
54 |
let hours = time.getHours() + '' |
|
55 |
let minute = time.getMinutes() + '' |
|
56 |
let second = time.getSeconds() + '' |
|
57 |
|
|
58 |
if (month < 10) { month = '0' + month } |
|
59 |
if (date < 10) { date = '0' + date } |
|
60 |
if (hours < 10) { hours = '0' + hours } |
|
61 |
if (minute < 10) { minute = '0' + minute } |
|
62 |
if (second < 10) { second = '0' + second } |
|
63 |
return year + '-' + month + '-' + date |
|
64 |
} |
|
65 |
export function getYM (timestamp: number | string | Date) { |
|
66 |
const time = new Date(timestamp) |
|
67 |
const year = time.getFullYear() |
|
68 |
let month = time.getMonth() + 1 + '' |
|
69 |
let date = time.getDate() + '' |
|
70 |
let hours = time.getHours() + '' |
|
71 |
let minute = time.getMinutes() + '' |
|
72 |
let second = time.getSeconds() + '' |
|
73 |
|
|
74 |
if (month < 10) { month = '0' + month } |
|
75 |
if (date < 10) { date = '0' + date } |
|
76 |
if (hours < 10) { hours = '0' + hours } |
|
77 |
if (minute < 10) { minute = '0' + minute } |
|
78 |
if (second < 10) { second = '0' + second } |
|
79 |
return year + '-' + month |
|
80 |
} |