用js获取实时的获取当前的年月日,时分秒,以及星期

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统时间</title>
<script language="javascript" type="text/javascript">
<!--
//获得当前时间,刻度为一千分一秒
var initializationTime=(new Date()).getTime();
function showLeftTime()
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var day=now.getDate();
var weekday=now.get
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
document.all.show.innerHTML=""+year+""+month+""+day+""+hours+":"+minutes+":"+seconds+"";
//一秒刷新一次显示时间
var timeID=setTimeout(showLeftTime,1000);
}

function showtime() {
var date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth() + 1;
this.date = date.getDate();
this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var currentTime = "现在是:" + this.year + "" + this.month + "" + this.date + "" + this.hour + ":" + this.minute + ":" + this.second + " " +"("+ this.day+")";
document.all.show.innerHTML=currentTime;
var timei=setTimeout(showtime,1000);}
//-->
</script>
</head>
<body onload="showtime()">
<label id="show">显示时间的位置</label>

</body>
</html>

 

posted @ 2013-07-13 19:22  Follow-your-heart  阅读(1392)  评论(0编辑  收藏  举报