使用js显示当前时间示例
页面前台显示
<spanid="clock"style="font-size:14px;"></span>
js脚本
$(document).ready(function(){
//第一种
showTime();
//第二种
varclock=newClock();
clock.display($("#clock"));
});
//显示系统当前时间处理第一种方法
functionshowTime(){
varmyArray=newArray(7);
varTD=newDate();
myArray[0]="星期日";
myArray[1]="星期一";
myArray[2]="星期二";
myArray[3]="星期三";
myArray[4]="星期四";
myArray[5]="星期五";
myArray[6]="星期六";
weekday=TD.getDay();
varh=TD.getHours();
varm=TD.getMinutes();
vars=TD.getSeconds();
varhstr=h;
varmstr=m;
varistr=s;
if(h<10){hstr="0"+h};
if(m<10){mstr="0"+m};
if(s<10){istr="0"+s};
$("#clock").innerHTML("当前时间:"+newDate().toLocaleDateString()+""+myArray[weekday]+""+hstr+":"+mstr+":"+istr);
setTimeout(showTime,1000);
}
//显示系统当前时间处理第二种方法
functionClock(){
vardate=newDate();
this.year=date.getFullYear();
this.month=date.getMonth()+1;
this.date=date.getDate();
this.day=newArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六")[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(){
returnthis.year+"-"+this.month+"-"+this.date;
};
this.toDetailDate=function(){
returnthis.year+"-"+this.month+"-"+this.date+""+this.hour+":"+this.minute+":"+this.second;
};
this.display=function(ele){
varclock=newClock();
ele.innerHTML=clock.toString();
window.setTimeout(function(){clock.display(ele);},1000);
};
}
相关文章
- c浅拷贝和深拷贝的区别_js中深拷贝和浅拷贝的区别
- Node.js爬虫之使用puppeteer爬取百度图片
- 【说站】js中事件捕获的实现
- JS获取当前年份_js获取当前时间年月日
- js数组扁平化 flat
- js倒计时详解编程语言
- 使用JS连接MySQL数据库:实现化繁为简(js连接mysql数据库)
- js的with语句使用方法
- 兼容IE与Firefox的js复制代码
- Html中JS脚本执行顺序简单举例说明
- 取得窗口大小兼容所有浏览器的js代码
- js对数组中的数字从小到大排序实现代码
- ie6下png图片背景不透明的解决办法使用js实现
- Js时间函数getYear()的使用问题探讨
- 使用js+jquery实现无限极联动
- js使用数组判断提交数据是否存在相同数据
- 使用js写的一个简易的投票
- 使用js实现关闭js弹出层的窗口
- node.js中的querystring.escape方法使用说明
- node.js中的buffer.toJSON方法使用说明
- node.js中的fs.truncate方法使用说明
- js的imageonload事件使用遇到的问题