Javascript擷取本周,本月,本季,本年,上月,上周,上季,去年,上二周,上二月

來源:互聯網
上載者:User

Javascript擷取本周,本月,本季,本年,上月,上周,上季,去年,上二周,上二月的時間段

function dateChange(name){var beginTimeObject = document.getElementById("beginTime");var endTimeObject = document.getElementById("endTime");var beginTime;var endTime;var now = new Date();var month = now.getMonth();var year = now.getFullYear();var day = now.getDate();var wday = now.getDay();switch(name){case "tweek": //本周var day  = now.getDay();now.setDate(now.getDate() - (day -1));beginTime = formatDate(now);now.setDate(now.getDate() + 6);endTime = formatDate(now);break;case "tmonth":  //本月now.setDate(1);beginTime = formatDate(now);var days = getDays(now);now.setDate(days);endTime = formatDate(now);break;case "tquarter":   //本季var m = now.getMonth() + 1;var q = parseInt((m + 2 ) / 3 ); //得到第幾季m = q * 3 - 2;  //得到季的首月份now.setMonth(m-1);now.setDate(1);beginTime = formatDate(now);now.setMonth(now.getMonth() + 3);now.setDate(0);endTime = formatDate(now);break;case "tyear":    //本年now.setMonth(0);now.setDate(1);beginTime = formatDate(now);now.setMonth(11);now.setDate(31);endTime = formatDate(now);        break;case "today":    //今天beginTime = formatDate(now);endTime = beginTime;break;case "pweek":    //上周var day  = now.getDay();now.setDate(now.getDate() - (day -1) - 7 );beginTime = formatDate(now);now.setDate(now.getDate() + 6);endTime = formatDate(now);break;case "pmonth":    //上月now.setDate(1);now.setMonth(now.getMonth() -1 );beginTime = formatDate(now);var days = getDays(now);now.setDate(days);endTime = formatDate(now);break;case "pquarter":    //上季var m = now.getMonth() + 1;var q = parseInt((m + 2 ) / 3 ); //得到第幾季m = q * 3 - 2;  //得到季的首月份m = m-3 ; //上季now.setMonth(m-1);now.setDate(1);beginTime = formatDate(now);now.setMonth(now.getMonth() + 3);now.setDate(0);endTime = formatDate(now);        break;case "pyear":    //去年now.setFullYear(now.getFullYear() -1 );now.setMonth(0);now.setDate(1);beginTime = formatDate(now);now.setMonth(11);now.setDate(31);endTime = formatDate(now);            break;case "p2week":    //上二周var day  = now.getDay();now.setDate(now.getDate() - (day -1) - 7 *2);beginTime = formatDate(now);now.setDate(now.getDate() + 6 + 7);endTime = formatDate(now);            break;case "p2month":    //上二月now.setDate(1);now.setMonth(now.getMonth() -1*2 );beginTime = formatDate(now);now.setMonth(now.getMonth() + 2);now.setDate(0);endTime = formatDate(now);break;case "customize":    //自訂beginTime = "";endTime = "";break;}beginTimeObject.value = beginTime;endTimeObject.value = endTime;}

 引自:http://hi.baidu.com/xixitie/item/b3d98eeca9d9633987d9de66

相關文章

聯繫我們

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