dateUtil.ts 537 字节
Newer Older
1 2 3
/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
V
vben 已提交
4
import dayjs from 'dayjs';
陈文彬 已提交
5

6
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
V
vben 已提交
7
const DATE_FORMAT = 'YYYY-MM-DD';
陈文彬 已提交
8

9
export function formatToDateTime(
V
vben 已提交
10
  date: dayjs.Dayjs | undefined = undefined,
V
vben 已提交
11
  format = DATE_TIME_FORMAT,
12
): string {
V
vben 已提交
13
  return dayjs(date).format(format);
陈文彬 已提交
14 15
}

V
vben 已提交
16 17 18 19 20
export function formatToDate(
  date: dayjs.Dayjs | undefined = undefined,
  format = DATE_FORMAT,
): string {
  return dayjs(date).format(format);
陈文彬 已提交
21 22
}

V
vben 已提交
23
export const dateUtil = dayjs;