<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html"; charset="utf-8"/>
<title>js输出当前时间到指定位置</title>
<style type="text/css">
#result{
width: 300px;height: 50px;margin: 10px auto;text-align: center;background: #ccc;
}
</style>
<script type="text/javascript">
window.onload = function(){
showTime();
};
function showTime(){
var date = new Date();var year = date.getFullYear();var month = date.getMonth()+1;var day = date.getDate();var h = date.getHours();var m = date.getMinutes();var s = date.getSeconds();m = checkTime(m);s = checkTime(s);var weekday=new Array(7);weekday[0]="星期日";weekday[1]="星期一";weekday[2]="星期二";weekday[3]="星期三";weekday[4]="星期四";weekday[5]="星期五";weekday[6]="星期六";var weekday = weekday[date.getDay()];
document.getElementById("result").innerHTML = (year+"."+month+"."+day+" "+weekday+" "+h+":"+m+":"+s);
}
function checkTime(i){
if(i<10){
i = "0"+i;
}return i;
}
</script>
</head>
<body>
<div id="result"></div>
</body>
</html>