日期:2014-05-17  浏览次数:20712 次

HTML 显示系统时间
代码1:(显示静态时间)

<script type="text/javascript">
var myDate = new Date();
document.write(myDate.toLocaleString())
</script>

代码2:(显示动态时间)

<script>
function show(){
var date = new Date(); //日期对象
var now = "";
now = date.getFullYear()+"年"; //读英文就行了
now = now + (date.getMonth()+1)+"月"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
now = now + date.getDate()+"日";
now = now + date.getHours()+"时";
now = now + date.getMinutes()+"分";
now = now + date.getSeconds()+"秒";
document.getElementById("nowDiv").innerHTML = now; //div的html是now这个字符串
setTimeout("show()",1000); //设置过1000毫秒就是1秒,调用show方法
}
</script>
<body onload="show()"> <!-- 网页加载时调用一次 以后就自动调用了-->
<div id="nowDiv"></div>
</body>

代码3:(显示动态时间)

<html>
<head>
<title>网页特效|Linkweb.cn/Js|---最简单的全日制时间显示,代码非常简单</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>

<div id="linkweb">
</div>
<script>setInterval("linkweb.innerHTML=new Date().toLocaleString()+' 星期'+'日一

二三四五六'.charAt(new Date().getDay());",1000);
</script>


</body>
</html>





用html语言来获取确实有点难度,这是用JS来做的放在文件里面可以在标题栏显示时间。
<SCRIPT LANGUAGE="JavaScript">
var clocktext;
var pagetitle = document.title;
function scroll() {
today = new Date();
sec = today.getSeconds();
hr = today.getHours();
min = today.getMinutes();
if (hr <= 9) hr = "0" + hr;
if (min <= 9) min = "0" + min;
if (sec <= 9) sec = "0" + sec;
var clocktext = " 现在时间是: " + hr + ":" + min + ":" + sec;
clocktimer = setTimeout("scroll()", 1000);
document.title = pagetitle + clocktext;
}
if (document.all) scroll();
</script>