const formatDate=(date)=> {//初始化时间
// 格式化日期为 YYYY-MM-DD HH:mm:ss
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
const now = new Date(); // 获取当前时间
// 格式化当前时间
startTime.value = formatDate(now);
// 计算一个小时后的时间
const oneHourLaterDate = new Date(now.getTime() + 60 * 60 * 1000);
// 格式化一个小时后的时间
endTime.value = formatDate(oneHourLaterDate);
标签:const,String,formatDate,padStart,时间,Vue3,date,小时,now From: https://blog.csdn.net/Llongfyjc/article/details/143111185