效果图:
代码:
function disptime(){
var time=new Date();
var hour=time.getHours();
var hello="";
if(hour>=0&&hour<=7){
hello="凌晨好!";
}else if(hour>7&&hour<=9){
hello="清晨好!";
}else if(hour>9&&hour<=12){
hello="上午好!";
}else if(hour>12&&hour<=13){
hello="中午好!";
}else if(hour>13&&hour<=17){
hello="下午好!";
}else if(hour>17){
hello="晚上好!";
}
var month="00"+String(time.getMonth()+1);
month=month.substring(month.length-2,month.length);
if(month=="00") month="12"
var day="00"+String(time.getDate());
day=day.substring(day.length-2,day.length);
var HH="00"+String(time.getHours());
HH=HH.substring(HH.length-2,HH.length);
var minute="00"+String(time.getMinutes());
minute=minute.substring(minute.length-2,minute.length);
var second="00"+String(time.getSeconds());
second=second.substring(second.length-2,second.length)
$("#hello").html(hello);
$("#time").html(month+"月"+day+"日"+" "+HH+":"+minute+":"+second+"");
setTimeout("disptime()",1000);
}