很多网页都有这样的功能,在网页的某一个地方能够显示当前系统的日期时间,这个功能是否能够对浏览者有多少帮助不得而知,因为每一台电脑都有这样的功能,不过既然有需要,作为程序员的我们就要实现,下面是一段这样的代码实例,希望能够给代码带来一定的帮助,代码实例如下:
   [ 其他 ] 运行代码    下载代码
<!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>

代码描述:js获取 当前日期时间。js实现的获取当前日期时间代码实例



203 271



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册



×
×
51前端

注册

×
绑定手机

请绑定手机号,在继续操作

×
单次下载支付

应付金额:279

支付完成后,回到下载页面,在进行下载

官方QQ群
意见反馈
qq群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到