这篇文章介绍了页面实时显示当前时间的简单实例
有需要的朋友可以参考需要
复制代码 代码如下:
<html>
<head>
<title>JavaScript实现页面实时显示当前时间</title>
</head>
<body>
<script language="javascript">
function showtime()
{
var todayhoursecondminuteyearmonthdate;
var strDate ;
today=new Date();
var n_day = todaygetDay();
switch (n_day)
{
case :{
strDate = "星期日"
}break;
case :{
strDate = "星期一"
}break;
case :{
strDate ="星期二"
}break;
case :{
strDate = "星期三"
}break;
case :{
strDate = "星期四"
}break;
case :{
strDate = "星期五"
}break;
case :{
strDate = "星期六"
}break;
case :{
strDate = "星期日"
}break;
}
year = todaygetYear();
month = todaygetMonth()+;
date = todaygetDate();
hour = todaygetHours();
minute =todaygetMinutes();
second = todaygetSeconds();
if(month<) month=""+month;
if(date<) date=""+date;
if(hour<) hour=""+hour;
if(minute<) minute=""+minute;
if(second<) second=""+second;
documentgetElementById(time)innerHTML = year + "年" + month + "月" + date + "日 " + strDate +" " + hour + ":" + minute + ":" + second; //显示时间
setTimeout("showtime();" ); //设定函数自动执行时间为 ms( s)
}
</script>
<div id="time"></div>
<script language="javascript"> showtime();</script>
</body>
</html>