/** * 获取实时日期与时间 * 应用:日期时钟 */ export function useRealTime () { const date = new Date() const dateObj: any = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate(), hour: date.getHours(), minute: date.getMinutes(), second: date.getSeconds(), dateDay: date.getDay() // 周几 } for (const [key, value] of Object.entries(dateObj)) { if ((value as number) < 10) { dateObj[key] = '0' + value } } const { year, month, day, hour, minute, second, dateDay } = dateObj const bigNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'] return { date: `${year}-${month}-${day}`, // 年月日 time: `${hour}:${minute}:${second}`, // 时分秒 day: bigNum[dateDay] // 周几(大写) } }