1. 程式人生 > >使用Jquery動態顯示年月日星期時間的程式碼段

使用Jquery動態顯示年月日星期時間的程式碼段

<script src="/js/jquery-1.8.3.min.js" type="text/javascript"></script>    

        function getDate() {
            var today = new Date();
            var date = today.getFullYear() + "年" + twoDigits(today.getMonth() + 1) + "月" + twoDigits(today.getDate()) + "日 ";
            var week = " 星期" + "日一二三四五六 ".charAt(today.getDay());
            var time = twoDigits(today.getHours()) + ":" + twoDigits(today.getMinutes()) + ":" + twoDigits(today.getSeconds());
            $(".date").html(date + week + time);
        }
        function twoDigits(val) {
            if (val < 10) return "0" + val; return val;
        }
        $(function () {
            setInterval(getDate, 1000);
        });

<div class="date">
</div>