分为凌晨、早上、中午、晚上
function formatDate(inputDate) {
const date = new Date(inputDate);
date.setHours(date.getHours() - 1);
const year = date.getFullYear();
const month = date.getMonth() + 1; // 月份从0开始
const day = date.getDate();
let hours = date.getHours();
const minutes = date.getMinutes();
const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
const weekDay = weekDays[date.getDay()];
let period;
if (hours >= 0 && hours < 6) {
period = '凌晨';
} else if (hours >= 6 && hours < 12) {
period = '早上';
} else if (hours === 12) {
period = '中午';
} else if (hours > 12 && hours < 18) {
period = '下午';
} else {
period = '晚上';
}
hours = hours % 12 || 12; // 转换为12小时制,0时为12时
const formattedHours = hours.toString().padStart(2, '0');
return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')} (${weekDay}) ${period} ${formattedHours}点`;
}