//显示时间日期
function showTime(){
var hour = new Date().getHours();
var timeShow = document.getElementById('timeShow');
if(hour > 5 && hour <= 8){ //6 7 8点多
timeShow.innerHTML = '早上好!';
}else if(hour > 8 && hour <= 12){ //9 10 11 12点多
timeShow.innerHTML = '上午好!';
}else if(hour > 12 && hour <= 17){ //13 14 15 16 17点多
timeShow.innerHTML = '下午好!';
}else if(hour > 17 && hour <= 18){ //18点多
timeShow.innerHTML = '傍晚好!';
}else if(hour > 18 && hour <= 21){ //19 20 21点多
timeShow.innerHTML = '晚上好!';
}else{
timeShow.innerHTML = '夜晚好!';
}
timeShow = document.getElementById("dateShow");//显示日期的地方
timeShow.innerHTML = '今天是 ' + new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());
}
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)