我们经常遇到项目中显示时间的问题。一般的处理方法是在前台控制JS。js控制时间显示代码如下所示。

复制代码代码如下所示:
函数时钟(){
日期=新日期();
this.year = date.getfullyear();
this.month = date.getmonth()+ 1;
this.date = date.getdate();
this.day =新的数组(星期日
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 =函数(){
现在是回报:+ this.year +年+ this.month +月+ this.date +日+ this.hour +:+ this.minute +:+ this.second ++这。天;
}; / /现在13:54:17:2013年3月6日星期三


复制代码代码如下所示:

this.tosimpledate =函数(){
返回this.year +-+ this.month +-+ this.date;
}; / / 2013-03-06

this.todetaildate =函数(){
返回this.year +-+ this.month +-+ this.date ++ this.hour +:+ this.minute +:+ this.second;
}; / / 2013-03-06 13:45:43

this.display =功能(ELE){
var时钟=新时钟();
ele.innerhtml =(时钟。toString); / /来电显示模式
Window.setTimeout(function(){ clock.display(ELE);},1000);
};
}