jquery取得本周,上一周,下一周的周一和周日

來源:互聯網
上載者:User

標籤:style   http   color   io   java   ar   art   cti   sp   

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="../JS/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        $(function () { obaganlestyle(1, 7);
        });
       
        function obaganlestyle(snum,lnum)
        {
            var myDate = new Date();
            var day = myDate.getDay();//返回0-6
            //var today = new Array(‘星期日‘, ‘星期一‘, ‘星期二‘, ‘星期三‘, ‘星期四‘, ‘星期五‘, ‘星期六‘);
            //當天的日期
            var endday;
            var startday;
         
            endday = getthisDay(-day + lnum); //算得周日
            startday = getthisDay(-day + snum);//算的周一
           
            $("#begintime").val(startday + " 00:00:00");
            $("#endtime").val(endday + " 59:59:59");
        }
        //取得日期
        function getthisDay(day) {
            var today = new Date();
            var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
            today.setTime(targetday_milliseconds); //關鍵
            var tyear = today.getFullYear();
            var tMonth = today.getMonth();
            var tDate = today.getDate();
            if (tDate < 10) {
                tDate = "0" + tDate;
            }
            tMonth = tMonth + 1;
            if (tMonth < 10) {
                tMonth = "0" + tMonth;
            }
            return tyear + "-" + tMonth + "-" + tDate + "";
        }

        //各種日期取得
        function getdaybytype(type) {
            switch (type) {
                case 1:
                    obaganlestyle(1, 7);
                    break;
                case 2:
                    obaganlestyle(0,-6);
                    break;
                case 3:
                    obaganlestyle(8, 14);
                    break;
                default:
                    break;
            }
        }
    </script>
</head>
<body>
    開始時間:<input type="text" id="begintime" value="" /><br />
    結束時間:<input type="text" id="endtime" value="">
    <input type="button" id="thisweek" onclick="getdaybytype(1)" value="這周" />
    <input type="button" id="onweek" onclick="getdaybytype(2)" value="上一周" />
    <input type="button" id="nextweek" onclick="getdaybytype(3)" value="下一周" />
</body>
</html>

jquery取得本周,上一周,下一周的周一和周日

聯繫我們

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