JavaScript - Date對象

來源:互聯網
上載者:User

標籤:javascript   function   date   對象   

Date對象
<html>    <head>        <title>Date對象</title>        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />        <script type="text/javascript">            function showCurrentTime(){                var today=new Date();                //document.writeln(today);                var year=today.getFullYear();                var month=today.getMonth()+1;                month=checkTime(month);                var date=today.getDate();                date=checkTime(date);                var hour=today.getHours();                hour=checkTime(hour);                var minute=today.getMinutes();                minute=checkTime(minute);                var second=checkTime(today.getSeconds());                var num=today.getDay();                var weekday;                switch(num){                    case 0:                        weekday="星期天";                        break;                    case 1:                        weekday="星期一";                        break;                    case 2:                        weekday="星期二";                        break;                }                $("currentTime").innerHTML=year+"年"+month+"月"+date+"日 "+hour+":"+minute+":"+second+" "+weekday;            }            setInterval("showCurrentTime()",1000);            function checkTime(i){                if(i<10){                    i="0"+i;                }                return i;            }            var timer;            function show(){                document.getElementById("info").innerHTML+="Hello World !<br/>";                timer=setTimeout("show()",500); //開啟一個計時器,並返回此計時器            }            //定時器setTimeout()            //setTimeout("show()",5000); //5秒後調用show()函數            //window.onload=show;            //            function getTitle(){                //alert(document.getElementById("title").innerHTML);                document.getElementById("title").innerHTML="你的我的大西瓜";            }            function startTimer(){                show();            }            function stopTimer(){                clearTimeout(timer);            }            //定時器setInterval()            function show2(){                document.getElementById("info").innerHTML+="Hello World !<br/>";            }            function startTimer2(){                timer=setInterval("show2()",500);            }            function stopTimer2(){                clearInterval(timer);            }            //簡化通過ID擷取元素            function $(id){                return document.getElementById(id);            }        </script>    </head>    <body>        <div id="currentTime"></div>        <hr/>        使用setTimeout()實現        <input type="button" value="走你...." onclick="startTimer()"/> &nbsp;&nbsp;        <input type="button" value="停..." onclick="stopTimer()"/><br/>        使用setInterval()實現        <input type="button" value="走你...." onclick="startTimer2()"/> &nbsp;&nbsp;        <input type="button" value="停..." onclick="stopTimer2()"/>        <div id="info"></div>        <h2 id="title">你是我的小呀小蘋果</h2>        <input type="button" value="擷取標題" onclick="getTitle()"/>    </body></html>

JavaScript - Date對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.