2021-03-12 21:40:23 +08:00
|
|
|
/**
|
|
|
|
|
* Independent time operation tool to facilitate subsequent switch to dayjs
|
|
|
|
|
*/
|
2021-11-10 22:12:10 +08:00
|
|
|
import dayjs from 'dayjs';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2021-10-29 20:09:43 +08:00
|
|
|
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
2021-11-11 22:28:39 +08:00
|
|
|
const DATE_FORMAT = 'YYYY-MM-DD';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2020-12-31 21:24:47 +08:00
|
|
|
export function formatToDateTime(
|
2021-11-10 22:12:10 +08:00
|
|
|
date: dayjs.Dayjs | undefined = undefined,
|
2021-08-24 22:41:48 +08:00
|
|
|
format = DATE_TIME_FORMAT,
|
2020-12-31 21:24:47 +08:00
|
|
|
): string {
|
2021-11-10 22:12:10 +08:00
|
|
|
return dayjs(date).format(format);
|
2020-09-28 20:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-10 22:12:10 +08:00
|
|
|
export function formatToDate(
|
|
|
|
|
date: dayjs.Dayjs | undefined = undefined,
|
|
|
|
|
format = DATE_FORMAT,
|
|
|
|
|
): string {
|
|
|
|
|
return dayjs(date).format(format);
|
2020-09-28 20:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-10 22:12:10 +08:00
|
|
|
export const dateUtil = dayjs;
|