首页 > 代码库 > jsp页面动态显示时间

jsp页面动态显示时间

<SCRIPT language="JavaScript">
  function disptime(){
  var time = new Date();
  var hour = time.getHours();
  var minute = time.getMinutes();
  var second = time.getSeconds();
  var year = time.getFullYear();
  var month = time.getMonth() + 1;
  var date = time.getDate();
  var day0 = time.getDay();
  var day = "";
  switch(day0){
    case 1:day = "星期一";break;
    case 2:day = "星期二";break;
    case 3:day = "星期三";break;
    case 4:day = "星期四";break;
    case 5:day = "星期五";break;
    case 6:day = "星期六";break;
    case 0:day = "星期日";break;
  }

      var apm="上午";
          if (hour>12){
            hour=hour-12;
            apm="下午" ;
          }  
  if (minute < 10)

  minute="0"+minute;
  if (second < 10)
  second="0"+second;
  var time = year + "/" + month + "/" + date + " " + day + " " + apm + " " + hour + ":" + minute + ":" + second;
  document.getElementById("clock").innerHTML = time;
  setTimeout("disptime()",1000);
   }
</SCRIPT>
<body leftmargin="0" topmargin="0" class="footer" onl oad="disptime()">
  <form NAME="myform">
    <span style="float:right" id="clock"></span>
    <span style="float:center">XXXXXXXXXXXXXXXXXX</span>
  </form>
</body>
</html>

 

PS:

IE中float布局将center写在前会导致right的换行显示,这时需要将right的写在前面,即可解决。

chrome中前后无影响。

jsp页面动态显示时间