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;
  }html

      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" onload="disptime()">
  <form NAME="myform">
    <span style="float:right" id="clock"></span>
    <span style="float:center">XXXXXXXXXXXXXXXXXX</span>
  </form>
</body>
</html>
chrome

 

PS:佈局

IE中float佈局將center寫在前會致使right的換行顯示,這時須要將right的寫在前面,便可解決。spa

chrome中先後無影響。orm

相關文章
相關標籤/搜索