网页中加入时间的代码
把如下代码加入<body>区域中
<script>setInterval("timenow.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
</script>
</script>
把如下代码放到你想显示的地方:
<div id="timenow"></div> 或者:<font id="timenow"></font>
另一种:
第一步:把如下代码加入<body>区域中
<SCRIPT LANGUAGE="javascript">
function gettime()
{ var t = new Date();
var hours = t.getHours();
var minutes = t.getMinutes();
var seconds = t.getSeconds();
var show_str ="";
show_str +=(hours > 12) ? "下午 ": "上午 ";
show_str += ((hours > 12) ? hours-12 : hours);
show_str += ((minutes <10) ? ":0" : ":") + minutes;
show_str += ((seconds <10) ? ":0" : ":") + seconds;
document.show_time.name1.value = show_str;
timerID = setTimeout("gettime()",1000);
}
</SCRIPT>
function gettime()
{ var t = new Date();
var hours = t.getHours();
var minutes = t.getMinutes();
var seconds = t.getSeconds();
var show_str ="";
show_str +=(hours > 12) ? "下午 ": "上午 ";
show_str += ((hours > 12) ? hours-12 : hours);
show_str += ((minutes <10) ? ":0" : ":") + minutes;
show_str += ((seconds <10) ? ":0" : ":") + seconds;
document.show_time.name1.value = show_str;
timerID = setTimeout("gettime()",1000);
}
</SCRIPT>
<FORM NAME="show_time" onSubmit="0">
现在时间是:
<INPUT TYPE="text" NAME="name1" SIZE=16 VALUE="">
</FORM>
第二步:把如下代码加入<body>区域中
<BODY onLoad="gettime()">