<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
var time=null;
function datetime()
{
var date=new Date();
//活得年月日
var str=date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日";
//活得时分秒
str=str+bb(date.getHours())+"时"+bb(date.getMinutes())+"分"+bb(date.getSeconds())+"秒";
var txttime=document.getElementById("txtdatetime");
txttime.innerText=str+""+week(date.getDay());
time=window.setTimeout("datetime()",1000);
}
function bb(dtime)
{
if(dtime<10)
{
return "0"+dtime;
}
else
{
return dtime;
}
}
function week(day)
{
switch(day)
{
case 0:
return "星期天";
break;
case 1:
return "星期一";
break;
case 2:
return "星期二";
break;
case 3:
return "星期三";
break;
case 4:
return "星期四";
break;
case 5:
return "星期五";
break;
case 6:
return "星期六";
break;
}
}
</script>
</head>
<body οnlοad="datetime()">
<form id="form1" runat="server">
<div>
<input id="txtdatetime" type="text" />
</div>
</form>
</body>
</html>
js中的时间对象(Date)
最新推荐文章于 2024-08-14 15:45:18 发布