Javascript acquisition this week, this month, this season, this year, last month, last week, last quarter, last year, last two weeks, last month

Source: Internet
Author: User

Javascript get this week, this month, this season, this year, last month, last week, last quarter, last year, last two weeks, last month

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 this week. getday (); now. setdate (now. getdate ()-(day-1); begintime = formatdate (now); now. setdate (now. getdate () + 6); endtime = formatdate (now); break; Case "tmonth": // This month now. setdate (1); begintime = formatdate (now); var days = getdays (now); now. setdate (days); endtime = formatdate (now); break; Case "tquarter": // var M = now this season. getmonth () + 1; var q = parseint (m + 2)/3); // obtain the quarter M = Q * 3-2; // get the first month of the season 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 this year. setmonth (0); now. setdate (1); begintime = formatdate (now); now. setmonth (11); now. setdate (31); endtime = formatdate (now); break; Case "today": // Today begintime = formatdate (now); endtime = begintime; break; Case "pweek ": // last week 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": // last month 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 in the previous quarter. getmonth () + 1; var q = parseint (m + 2)/3); // obtain the quarter M = Q * 3-2; // get the first month of the quarter M = m-3; // The last season now. setmonth (m-1); now. setdate (1); begintime = formatdate (now); now. setmonth (now. getmonth () + 3); now. setdate (0); endtime = formatdate (now); break; Case "pyear": // last year 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 in the last two weeks. getday (); now. setdate (now. getdate ()-(day-1)-7*2); begintime = formatdate (now); now. setdate (now. getdate () + 6 + 7); endtime = formatdate (now); break; Case "p2month": // last month 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": // custom begintime = ""; endtime = ""; break;} begintimeobject. value = begintime; endtimeobject. value = endtime ;}

From: http://hi.baidu.com/xixitie/item/b3d98eeca9d9633987d9de66

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.