时间

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>时间</title>
  <script type="text/javascript">
  window.onload=distime
  function distime()
  {
  var time = new Date();
  var y=time.getFullYear();
  var m=time.getMonth()+1;
  var d=time.getDate();
  var w=time.getDay();
  var hour = time.getHours();
  var minute = time.getMinutes();
  var second = time.getSeconds();
  var apm="AM";
  if (hour>12)
  {
  hour=hour-12;
  apm="PM" ;
  }
  if (minute < 10)
  minute="0"+minute;
  if (second < 10)
  second="0"+second;
   
  var tstr='今天是:'+y+"年"+m+"月"+d+"日"+"星期"+w+"&nbsp;&nbsp;&nbsp;&nbsp;"+hour+":"+minute+":"+second+apm;
   
  document.getElementById("myclock").innerHTML=tstr;
  }
   
  window.setInterval("distime()",1000);
   
   
   
   
  </script>
   
  </head>
   
  <body>
  <div id="myclock">
   
  </div>
  </body>
  </html>
 

你可能感兴趣的:(JavaScript)