vue-vben-admin/src/utils/dateUtil.ts

24 lines
537 B
TypeScript
Raw Normal View History

/**
* 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
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
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,
): 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;