根據日期判斷 該日期是本月的第幾周

來源:互聯網
上載者:User
var getMonthWeek = function (a, b, c) { /* a = d = 當前日期 b = 6 - w = 當前周的還有幾天過完(不算今天) a + b 的和在除以7 就是當天是當前月份的第幾周 */var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate(); return Math.ceil( (d + 6 - w) / 7 ); };var getYearWeek = function (a, b, c) { /* date1是當前日期 date2是當年第一天 d是當前日期是今年第多少天 用d + 當前年的第一天的周差距的和在除以7就是本年第幾周 */var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1), d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000); return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 ); }; /* today=new Date();//擷取目前時間*/var y = smonth[0];//年var m = smonth[1];//月var d = smonth[2]; //日alert(getMonthWeek(y, m, d));

聯繫我們

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