JS動態時間顯示(包含星期)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page language="java" %>
<%@ page contentType="text/html;charset=UTF-8"%>
    <head>
    <title>JS動態時間顯示</title>
    <script type="text/javascript">
        function $(id){
            return document.getElementById(id);
        }   
        function showTime(){
            dt = new Date();
            var show_day=new Array('星期一','星期二','星期三','星期四','星期五','星期六','星期日');
            year=dt.getFullYear();
            month=dt.getMonth()+1;
            date=dt.getDate();
            day=dt.getDay()-1;
            hours=dt.getHours();
            hours=hours<10?"0"+hours:hours;
            minutes=dt.getMinutes();
            minutes=minutes<10?"0"+minutes:minutes;
            seconds=dt.getSeconds();
            seconds=seconds<10?"0"+seconds:seconds;
            dtime = "當前時間是:"+year+"年"+month+"月"+date+"日 "+hours+"點"+minutes+"分"+seconds+"秒 "+show_day[day];
            $("nowTime").innerHTML = dtime;
            setTimeout("showTime()",1000);
        }
    </script>
    <style>
         .time{
            width:100%;
            margin:200px auto;
            border:3px red solid;
            text-align:center;
            font-size:42pt;
            color:#6090dd;
         }
    </style>
    </head>
    <body onload="showTime()">
        <div id="nowTime" class="time"></div>
    </body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章