JavaScript 动态显示系统时间

JavaScript 动态显示系统时间

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script language="javascript" type="text/javascript">
        //动态显示当前的时间
        function GetTime(obj)
        {
            var myDate = new Date();
            var Today = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
            //获取当前年
            var Years = myDate.getFullYear();
            //获取当前月
            var Months = myDate.getMonth() + 1;
            //获取当前日
            var Dates = myDate.getDate();
           
            //获取当前天是当前周的第几天
            var Days = Today[myDate.getDay()];
           
            //获取当前的时
            var Hours = myDate.getHours();
            //获取当前的分
            var Minutes = myDate.getMinutes();
            //获取当前的秒
            var Seconds = myDate.getSeconds();
           
            Months = Months < 10 ? '0' + Months : Months; 
            Dates = Dates < 10 ? '0' + Dates : Dates;
           
            Hours = Hours < 10 ? '0' + Hours : Hours;
            Minutes = Minutes < 10 ? '0' + Minutes : Minutes;
            Seconds = Seconds < 10 ? '0' + Seconds : Seconds;
                        
            obj.value = Years + '年' + Months + '月' + Dates + '日' + ' ' + Days + ' ' + Hours + ':' + Minutes  + ':' + Seconds;

            //每隔一秒重新调用GetTime函数
            setTimeout("GetTime(document.getElementById('ShowTime'))","1000");     
        }
    </script>

</head>
<body onload="GetTime(document.getElementById('ShowTime'))">
    <form id="form1" runat="server">
        <div>
            <input id="ShowTime" type="text" style="width: 511px" />
        </div>
    </form>
</body>
</html>








http://www.cnblogs.com/ziyun/archive/2010/01/26/1656620.html

你可能感兴趣的:(JavaScript,html)