数码资讯
js控件日期显示的一个小例子
我们经常遇到项目中显示时间的问题。一般的处理方法是在前台控制JS。js控制时间显示代码如下所示。 复制代码代码如下所示: 函数时钟(){ 日期=新日期(); this.year = date.getfullyear(); this.month = date.getmonth()+ 1; this.d
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
我们经常遇到项目中显示时间的问题。一般的处理方法是在前台控制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);
};
}
复制代码代码如下所示:
函数时钟(){
日期=新日期();
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);
};
}
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。