1.获取当前时间
<script type="text/javascript">
var now=new Date();
var hour=now.getHours();var minu=now.getMinut();
alert("您好!现在是"+hour+":"+minu+"\r欢迎访问明日科技图书网!");
</script>
2.获取今天星期几
var now=new Date();
var week=now.getDay();
switch(week){
case 1:
alert("星期一");break;
case 2:
alert("星期二");break;
case 3:
alert("星期三");break;
case 4:
alert("星期四");break;
case 5:
alert("星期五");break;
case 6:
alert("星期六");break;
case 7:
alert("星期天");break;
default:
alert("出错了!");
}
3.获取年月日星期几
function getClock(clock){
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth();
var date=now.getDate();
var day=now.getDay();
var arr_week=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var week=arr_week[day];
var time=year+"年"+month+"月"+date+"日"+week;
clock.innerHTML="系统公告:"+time;
}