Files
xj-screen/src/utils/utils.ts
T
2023-12-19 10:46:50 +08:00

41 lines
1.0 KiB
TypeScript

import dayjs from 'dayjs';
export function getZero(num: any) {
if (num < 10) {
return '0' + num;
}
return num;
}
export function useTopTime() {
const timeLeft = dayjs().format('YYYY年MM月DD日 HH时mm分ss秒');
const timeRight =
dayjs().diff(dayjs('2018-10-01'), 'day') +
'天' +
getZero(dayjs().diff(dayjs(dayjs().format('YYYY-MM-DD') + ' 00:00:00'), 'hours')) +
'时' +
getZero(dayjs().diff(dayjs(dayjs().format('YYYY-MM-DD HH') + ':00:00'), 'minutes')) +
'分' +
getZero(dayjs().diff(dayjs(dayjs().format('YYYY-MM-DD HH:mm') + ':00'), 'seconds')) +
'秒';
return {
timeLeft,
timeRight,
};
}
export function getToday() {
return dayjs().format('YYYY-MM-DD');
}
//分钟转小时
export function minuteToStr(minutes) {
// debugger;
if (!minutes) return '0分';
let h = Math.floor(minutes / 60);
let m = Math.floor(minutes % 60);
if (h) {
return `${h}小时${m > 0 ? `${m}分钟` : ''}`;
}
return `${m}分钟`;
}