eight
2025-03-31 54081618d902a83db25b8b9a54872b593034c2c9
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
// TODO 芋艿:【锁屏】可能后面删除掉
import dayjs from 'dayjs'
 
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
const DATE_FORMAT = 'YYYY-MM-DD'
 
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 curDayStart() {
  return dayjs().startOf('date').format(DATE_TIME_FORMAT)
}
 
export function curDayEnd() {
  return dayjs().endOf('date').format(DATE_TIME_FORMAT)
}
 
export function formatTimestamp(_date: Date) {
  return dayjs(_date).format("YYYY-MM-DD")
}
 
export function calculateAge( _birthDay: Date) {
  const birthday = dayjs(_birthDay);
  const today = dayjs(new Date());
  return today.diff(birthday, 'year');
}
 
export function calculateHours( start: Date, end: Date) {
  return  dayjs(end).diff(dayjs(start), 'hour');
}
 
export function isCurrentDay( _date: Date) {
  const today = dayjs(new Date());
  return today.isSame( dayjs(_date), 'day' )
}
 
export const dateUtil = dayjs