html显示时间代码怎么写

1.html显示时间代码时间js代码:Clock.js文件
function Clock() {
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();
this.toString = function() {
return this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;
};
this.toSimpleDate = function() {
return this.year + "-" + this.month + "-" + this.date;
};
this.toDetailDate = function() {
return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
};
this.display = function(ele) {
var clock = new Clock();
ele.innerHTML = clock.toString();
window.setTimeout(function() {clock.display(ele);}, 1000);
};
}
需要显示时间的页面
<SCRIPT src="http://www.xuexi88.com/zhishi/js/Clock.js" type=text/javascript></SCRIPT>; //引入Clock.js文件,注意路径
<label id=clock></label>; //放入标签,插入时间
<SCRIPT type=text/javascript>; //实例化clock对象
var clock = new Clock();
clock.display(document.getElementById("clock"));
</SCRIPT>
2.如何用html写代码,使得在网页上显示当前的时间和日期安装如下步骤操作: 1.在电脑磁盘空白出右键-新建,点击文档 2.将文档命名为index,用记事本打开 3. 写入一下代码,如图:<meta "/> 时间的动态显示<body> 4.在html头部写入获取时间的代码,如图 5. 在内容部分写入div标签,并附上ID,用来加载时间的载体 。
如图: 6.在头部写入div的样式如图,并保存 <style> .time1{width:100%; height:50px; background:#FFF000; line-height:50px; text-align:center;} </style> 7.保存后,将文件后缀命名为html 。点击查看,勾选文件扩展名 8.文件后缀命名由txt改为html 9.使用浏览器打开文件 10.可以看到编写的文件,网页显示时间了 。
3.html如何显示时间<html>
<head>
<;!-- 请把这段放在 head 里面 -->
<script type="text/javascript" language="javascript1.5">
<!--
window.onload = theClock
function theClock() {
now = new Date;
theTime = ((now.getHours() > 0 && now.getHours() < 13)) ? now.getHours() : (now.getHours() == 0) ? 12 : now.getHours()-12;
theTime += (now.getMinutes() > 9) ? ":" + now.getMinutes() : ":0" + now.getMinutes();
theTime += (now.getSeconds() > 9) ? ":" + now.getSeconds() : ":0" + now.getSeconds();
theTime += (now.getHours() < 12) ? " am" : " pm";
clockSpan = document.getElementById("myClock");
clockSpan.replaceChild(document.createTextNode(theTime), clockSpan.firstChild);
setTimeout("theClock()",1000);
【html显示时间代码怎么写】}
// End hiding script from old browsers -->
</script>
<;!-- 这里结束 -->
</head>
<body>
<;!-- 请把下面这一行放在 body 里面 -->
现在的时间是 <span id="myClock">?</span>
</body>
</html>
================================================================
%回复楼上第2个问题
%把下面这两行放在你的 document.write( 上面
var m = today.getMonth()+1
if (m<10){ m ="0" + m};
%然后document.write( 里面用下面这行代替月份