// JavaScript Document //定义一个用asp直接取得的服务器时间对象 function serverTime(){ var tmpstr="2008-11-21 14:9:44"; this.currTime=new Date(tmpstr.replace(/-/gi,"/")); var othis=this; this.timeOut=window.setTimeout(function(){othis.increaseTime();},1000); } serverTime.prototype.increaseTime=function(){ this.currTime=new Date(Number(this.currTime)+990); //alert (this.currTime) var othis=this; this.timeOut=window.setTimeout(function(){othis.increaseTime();},1000); } //************************************************************************ //定义一个用于显示日期时间的类,根据serverTime来指定显示的是本地时间还是服务器时间。 function showTime(timeFormat,objTime){ this.timer=null; this.timeFormat=timeFormat; if (objTime==null){ this.currTime=this.getTime(); this.oServerTime=null; }else{ this.oServerTime=objTime this.currTime=objTime.currTime; } this.showContainer=null; this.doTimes=0 } showTime.prototype.getTime=function(){ return new Date(); } //中文日期显示 //星期 showTime.prototype.getCnWeekDay=function (numWDay){ switch(numWDay){ case "0": return "日"; case "1": return "一"; case "2": return "二"; case "3": return "三"; case "4": return "四"; case "5": return "五"; case "6": return "六"; } } //中文显示入口 showTime.prototype.showCnTotal=function(){ var tmpstr=" "; tmpstr+=this.currTime.getYear(); tmpstr+="年"; tmpstr+=this.currTime.getMonth()+1; tmpstr+="月"; tmpstr+=this.currTime.getDate(); tmpstr+="日"; /*tmpstr+=this.currTime.getHours(); tmpstr+="时"; tmpstr+=this.currTime.getMinutes(); tmpstr+="分"; tmpstr+=this.currTime.getSeconds(); tmpstr+="秒";*/ tmpstr+=" 星期" tmpstr+=this.getCnWeekDay(this.currTime.getDay().toString()); /*tmpstr+=this.doTimes;*/ return tmpstr; } //英文日期显示 //月份 showTime.prototype.getEnMouthWhole=function (month){ if (isNaN(Number(month))) return month switch(parseInt(month)){ case 0: return "January";break; case 1: return "February";break; case 2: return "March";break; case 3: return "April";break; case 4: return "May";break; case 5: return "June";break; case 6: return "July";break; case 7: return "August";break; case 8: return "September";break; case 9: return "October";break; case 10: return "November";break; case 11: return "December";break; default: return month;break; } } //星期 showTime.prototype.getEnWeekDayWhole=function(weekday){ if (isNaN(Number(weekday))) return weekday switch(parseInt(weekday)){ case 1: return "Monday";break; case 2: return "Tuesday";break; case 3: return "Wednesday";break; case 4: return "Thursday";break; case 5: return "Friday";break; case 6: return "Saturday";break; case 0: return "Sunday";break; default: return weekday;break; } } //英文日期显示入口 showTime.prototype.showEnTotal=function(){ var tmpstr="UTC+8 "; tmpstr+=this.getEnWeekDayWhole(this.currTime.getDay())+" "; tmpstr+=this.getEnMouthWhole(this.currTime.getMonth())+" "; tmpstr+=this.currTime.getDate()+" "; /*tmpstr+=this.currTime.getHours()+":"; tmpstr+=this.currTime.getMinutes()+" ";*/ tmpstr+=this.currTime.getYear(); /*tmpstr+=this.doTimes;*/ return tmpstr; } //每隔一秒钏刷亲一次页面。 showTime.prototype.doShowTime=function(){ //this.doTimes++; if (this.oServerTime==null) this.currTime=this.getTime(); else this.currTime=this.oServerTime.currTime; switch (this.timeFormat){ case "cn_total": if (this.showContainer==null){ var othis=this; window.clearTimeout(this.timer); this.timer=window.setTimeout(function(){othis.doShowTime();},1000); return this.showCnTotal(); }else{ var othis=this; window.clearTimeout(this.timer); this.timer=window.setTimeout(function(){othis.doShowTime();},1000); this.showContainer.innerHTML=this.showCnTotal(); } break; case "en_total": if (this.showContainer==null){ var othis=this; window.clearTimeout(this.timer); this.timer=window.setTimeout(function(){othis.doShowTime();},1000); return this.showEnTotal(); }else{ var othis=this; window.clearTimeout(this.timer); this.timer=window.setTimeout(function(){othis.doShowTime();},1000); this.showContainer.innerHTML=this.showEnTotal(); } break; } }