2021-10-20 14:32:09 +08:00
|
|
|
/**
|
|
|
|
* Independent time operation tool to facilitate subsequent switch to dayjs
|
|
|
|
*/
|
2022-09-22 14:04:19 +08:00
|
|
|
import dayjs from 'dayjs';
|
2021-10-20 14:32:09 +08:00
|
|
|
|
2022-09-27 19:31:09 +08:00
|
|
|
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
|
|
|
const DATE_FORMAT = 'YYYY-MM-DD';
|
2021-10-20 14:32:09 +08:00
|
|
|
|
2022-09-27 19:31:09 +08:00
|
|
|
export function formatToDateTime(date: dayjs.Dayjs | undefined = undefined, format = DATE_TIME_FORMAT): string {
|
2022-09-22 14:04:19 +08:00
|
|
|
return dayjs(date).format(format);
|
2021-10-20 14:32:09 +08:00
|
|
|
}
|
|
|
|
|
2022-09-27 19:31:09 +08:00
|
|
|
export function formatToDate(date: dayjs.Dayjs | undefined = undefined, format = DATE_FORMAT): string {
|
2022-09-22 14:04:19 +08:00
|
|
|
return dayjs(date).format(format);
|
2021-10-20 14:32:09 +08:00
|
|
|
}
|
|
|
|
|
2022-09-22 14:04:19 +08:00
|
|
|
export const dateUtil = dayjs;
|