functionformatDate(date){// 处理ISO 8601字符串if(typeof date ==='string'){
date =newDate(date);}// 处理时间戳elseif(typeof date ==='number'){
date =newDate(date *1000);// 假设后端时间戳为秒,需要乘以1000转换为毫秒}// 自定义格式化,例如转换为YYYY-MM-DD-HH-MM-SSconst year = date.getFullYear();const month =String(date.getMonth()+1).padStart(2,'0');// 月份是从0开始的,所以要+1const 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}`;}