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>