Home  >  Article  >  Web Front-end  >  Realizing dynamic clock effect based on javascript_javascript skills

Realizing dynamic clock effect based on javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:13:201579browse

The example in this article explains how to implement the dynamic clock effect in JavaScript and shares it with everyone for your reference. The specific content is as follows

Implementation code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>动态时钟</title>
<script type="text/javascript">
//在网页上输出:今天的日期、星期、现在的时间(动态时钟)
function start()
{
  var today=new Date();
  var year=today.getFullYear();
  var month=today.getMonth()+1;
  var day=today.getDate();
  var hours=today.getHours();
  var minutes=today.getMinutes();
  var seconds=today.getSeconds();
  //如果是单位数字,前面补0
  month=month<10&#63; "0"+month :month;
  day=day<10&#63; "0"+day :day;
  hours=hours<10&#63; "0"+hours :hours;
  minutes=minutes<10&#63; "0"+minutes :minutes;
  seconds=seconds<10&#63; "0"+seconds :seconds;
  //时间信息连成字符串
  var str="今天是"+year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds;
  //获取id=result的内容
  var obj=document.getElementById("result");
  obj.innerHTML=str;
  //延时器
  window.setTimeout("start()",1000);
}
</script>
</head>
 
<body onload="start()">
<div id="result"></div>
</body>
</html>

I hope this article will be helpful to everyone in learning javascript programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn