原創javascript顯示時間日期代碼

今天折騰了半天調了一個關於定點顯示時間和日期的JS代碼,根據設計的id號定點輸入即可,原代碼在下面,如有需改進的地方請指正,謝謝

 

<html><style type="text/css">

<!--

.STYLE1 {

       font-family: "Times New Roman", Times, serif;

       color: #000099;

}

-->

</style>

<script language=JavaScript>

function displayTimeAndDate(){

       showtime ();

       showdate ();

}

function showtime () {

if(!document.layers&&!document.all) return;

var now = new Date();

var hours = now.getHours();

var minutes = now.getMinutes();

var seconds = now.getSeconds();

var timeValue = "" +((hours >= 12) ? "下午 " : "上午 " );

timeValue += ((hours >12) ? hours -12 :hours);

timeValue += ((minutes < 10) ? ":0" : ":") + minutes;

timeValue += ((seconds < 10) ? ":0" : ":") + seconds;

if(document.layers){

 

              document.layers.bjsascClock.document.write(myclock);

 

              document.layers.bjsascClock.document.close();

 

}else if(document.all)

              clock.innerHTML = timeValue;

timerID = setTimeout("showtime()",1000);

}

 

function showdate () {

if(!document.layers&&!document.all) return;

       var today = new Date();

       var d=new initArray(

       "星期日",

       "星期一",

       "星期二",

       "星期三",

       "星期四",

       "星期五",

       "星期六");

       var dateValue = today.getYear()+""+(today.getMonth()+1)+""+today.getDate()+""+" "+d[today.getDay()+1];

       if(document.layers){

 

              document.layers.bjsascClock.document.write(myclock);

 

              document.layers.bjsascClock.document.close();

 

       }else if(document.all)

              datediv.innerHTML = dateValue;

}

function initArray(){

this.length=initArray.arguments.length

for(var i=0;i<this.length;i++)

this[i+1]=initArray.arguments[i] }

</SCRIPT>

<body οnlοad=displayTimeAndDate()>

<table width="600" border="0" align="left">

<tr height="5">

<td >

          <div align="left" width="500">

                                                                      <table width="480" border="0" align="right">

                                                                             <tr height="5">

                                                                                    <td width=60>

                                                                                           歡迎您

                                                                                    </td>

                                                                                    <td width=70>

                                                                                    雷明                                                                                </td>

                                                                                    <td width=80>

                                                                                           當前時間:

                                                                                    </td>

                                                                                    <td width=100>

                                                                                           <span id=clock style=font-family:Arial;></span>

                                                                                    </td>

                                                                                    <td width=190>

                                                                                           <span id=datediv style=font-family:Arial;></span>

                                                                                    </td>

                                                                             </tr>

                                                                      </table>

                                                               </div>

</td></tr></table>                                                         

 

</body>

</html>

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章