您的位置:首页 > Web前端 > JavaScript

原创javascript显示时间日期代码

2007-05-31 14:13 686 查看
今天折腾了半天调了一个关于定点显示时间和日期的JS代码,根据设计的id号定点输入即可,原代码在下面,如有需改进的地方请指正,谢谢

<html><style type="text/css">
<!--
.STYLE1 {
font-family: "Times New Roman", Times, serif;
color: #000099;
}
-->
</style>
<script language=JavaScript>
function displayTimeAndDate(){
showtime ();
showdate ();
}
function showtime () {
if(!document.layers&&!document.all) return;
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeValue = "" +((hours >= 12) ? "下午 " : "上午 " );
timeValue += ((hours >12) ? hours -12 :hours);
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
if(document.layers){

document.layers.bjsascClock.document.write(myclock);

document.layers.bjsascClock.document.close();

}else if(document.all)
clock.innerHTML = timeValue;
timerID = setTimeout("showtime()",1000);
}

function showdate () {
if(!document.layers&&!document.all) return;
var today = new Date();
var d=new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六");
var dateValue = today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日"+" "+d[today.getDay()+1];
if(document.layers){

document.layers.bjsascClock.document.write(myclock);

document.layers.bjsascClock.document.close();

}else if(document.all)
datediv.innerHTML = dateValue;
}
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
</SCRIPT>
<body onload=displayTimeAndDate()>
<table width="600" border="0" align="left">
<tr height="5">
<td >
<div align="left" width="500">
<table width="480" border="0" align="right">
<tr height="5">
<td width=60>
欢迎您
</td>
<td width=70>
雷明 </td>
<td width=80>
当前时间:
</td>
<td width=100>
<span id=clock style=font-family:Arial;></span>
</td>
<td width=190>
<span id=datediv style=font-family:Arial;></span>
</td>
</tr>
</table>
</div>
</td></tr></table>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: