dateUtil.ts 626 B

12345678910111213141516171819202122
  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(
  8. date: dayjs.ConfigType | undefined = undefined,
  9. format = DATE_TIME_FORMAT,
  10. ): string | undefined {
  11. if (!date) return undefined;
  12. return dayjs(date).format(format);
  13. }
  14. export function formatToDate(date: dayjs.ConfigType | undefined = undefined, format = DATE_FORMAT): string | undefined {
  15. if (!date) return undefined;
  16. return dayjs(date).format(format);
  17. }
  18. export const dateUtil = dayjs;