Blame view

src/utils/dateUtil.ts 537 Bytes
1
2
3
/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
4
import dayjs from 'dayjs';
陈文彬 authored
5
6
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
vben authored
7
const DATE_FORMAT = 'YYYY-MM-DD';
陈文彬 authored
8
9
export function formatToDateTime(
10
  date: dayjs.Dayjs | undefined = undefined,
vben authored
11
  format = DATE_TIME_FORMAT,
12
): string {
13
  return dayjs(date).format(format);
陈文彬 authored
14
15
}
16
17
18
19
20
export function formatToDate(
  date: dayjs.Dayjs | undefined = undefined,
  format = DATE_FORMAT,
): string {
  return dayjs(date).format(format);
陈文彬 authored
21
22
}
23
export const dateUtil = dayjs;