window.onload = function (){
var oDoc = document,
oNewDiv = oDoc.createElement("div"),
GetDate = function(oDate){
this.y = oDate.getFullYear();
this.mo = oDate.getMonth()+1;
this.d = oDate.getDate();
this.h = oDate.getHours();
this.m = oDate.getMinutes();
this.s = oDate.getSeconds();
};
GetDate.prototype = {
showTime : function(){
var arr = [];
arr[0] = this.y + "年";
arr[1] = this.mo + "月";
arr[2] = this.d + "日";
arr[3] = this.h + "时";
arr[4] = this.m + "分";
arr[5] = this.s + "秒";
return arr.join("");
},
fnPrint: function(dom){
dom.innerHTML = "当前时间: " + this.showTime();
}
};
var oNow = new GetDate(new Date());
oNewDiv.id = "showTime";
oNewDiv.innerHTML = document.body.appendChild(oNewDiv);
var oDiv = oDoc.getElementById("showTime");
oNow.fnPrint(oDiv);
setInterval(function(){
var oNow2 = new GetDate(new Date());
oNow2.fnPrint(oDiv);
},1000);
}
如果您觉得本文的内容对您的学习有所帮助:
关键字:
js时间类 原创