dateUtil.ts 523 B

1234567891011121314151617
  1. /**
  2. * Independent time operation tool to facilitate subsequent switch to dayjs
  3. */
  4. import dayjs from 'dayjs';
  5. const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
  6. const DATE_FORMAT = 'YYYY-MM-DD';
  7. export function formatToDateTime(date: dayjs.Dayjs | undefined = undefined, format = DATE_TIME_FORMAT): string {
  8. return dayjs(date).format(format);
  9. }
  10. export function formatToDate(date: dayjs.Dayjs | undefined = undefined, format = DATE_FORMAT): string {
  11. return dayjs(date).format(format);
  12. }
  13. export const dateUtil = dayjs;