huangyinfeng
2024-09-20 74a35fac4332a8b060a92c605524ed12faf2755a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import dayjs from 'dayjs';
 
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_FORMAT = 'YYYY-MM-DD';
const DATE_DAY_FORMAT = 'YYYY-MM-DD HH:mm';
 
 
export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
  return dayjs(date).format(format);
}
 
export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string {
  return dayjs(date).format(format);
}
export function formatToDateDay(date?: dayjs.ConfigType, format = DATE_DAY_FORMAT): string {
  return dayjs(date).format(format);
}
export function isBeforeToDay(date?: dayjs.ConfigType): boolean {
  //获取今天的日期
  const now = dayjs();
  return dayjs(date).isBefore(dayjs(now));
}
 
export const dateUtil = dayjs;