代码描述:js获取 当前日期时间。js实现的获取当前日期时间代码实例
很多网页都有这样的功能,在网页的某一个地方能够显示当前系统的日期时间,这个功能是否能够对浏览者有多少帮助不得而知,因为每一台电脑都有这样的功能,不过既然有需要,作为程序员的我们就要实现,下面是一段这样的代码实例,希望能够给代码带来一定的帮助,代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.51qianduan.com/" /> <title>51前端</title> <style type="text/css"> #timer{ width:350px; height:30px; margin:0px auto; text-align:center; } </style> <script type="text/javascript"> function Clock() { var date = new Date(); this.year = date.getFullYear(); this.month = date.getMonth() + 1; this.date = date.getDate(); this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[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; }; } window.onload=function(){ var timer=document.getElementById("timer"); timer.innerHTML=new Clock().toString(); } </script> </head> <body> <div id="timer"></div> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能