js的時間函數實現一個電子錶

來源:互聯網
上載者:User

標籤:建立   作者   載入   表示   head   logs   tle   title   class   

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>    </head>    <body  onload="startime()">//這裡的onload的用途就是頁面在被載入的時候,就執行了函數startime()        <div id="div" style="border: 1px solid royalblue;floating:left; margin:0 auto; display:inline;"></div>        <script>                         //var  date=new Date();            // document.write(date);            //document.write(date.getFullYear());//輸出的是年份            //document.write(date.getDay());//輸出的是具體的星期幾            //document.write(date.getTime());//輸出的是一個時間戳記            //date.setFullYear(2011,2,3);//自己設定了時間            //document.write(date);            function startime(){                var t=new Date();//建立一個date的對象,才可以引用相關的date                var h=t.getHours();                var m=t.getMinutes();                var s=t.getSeconds();                document.getElementById("div").innerHTML=h+‘:‘+m+‘:‘+s;                m=checktime(m);                s=checktime(s);                t=setTimeout("startime()",500 );//注意一下函數的的參數的使用,第一個參數是要加上引號的,這裡呢重新調用了原來的函數,實現了重新整理的功能
//第二個參數是表示重新整理的時間,500表示的是0.5秒 } function checktime(i) {//這裡只是為了美觀一點 ,在個位元的面前,將數位顯示+一個0 if(i<10) { i="0"+i; } return i; } </script> </body></html><!-- [email protected] 時間:2017-03-11 描述:時間戳記的定義: 時間戳記是指格林威治時間1970年01月01日00時00分00秒 (北京時間1970年01月01日08時00分00秒)起至現在的總秒數。-->

 

js的時間函數實現一個電子錶

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.