JS get this week, this quarter, this month, the last month's start date, stop date

Source: Internet
Author: User

JS Code/** * Get the start date and stop date for this week, this quarter, this month, last month*/ varnow =NewDate ();//Current DatevarNowdayofweek = Now.getday ();//the day of the week todayvarNowday = Now.getdate ();//Current DayvarNowmonth = Now.getmonth ();//Current MonthvarNowyear = Now.getyear ();//Current yearNowyear + = (Nowyear < 2000)? 1900:0;//varLastmonthdate =NewDate ();//Last month dateLastmonthdate.setdate (1); Lastmonthdate.setmonth (Lastmonthdate.getmonth ()-1); varLastYear =lastmonthdate.getyear ();varLastmonth =lastmonthdate.getmonth ();//Format Date: Yyyy-mm-ddfunctionformatdate (date) {varMyyear =date.getfullyear ();varMymonth = Date.getmonth () +1; varMyweekday =date.getdate ();if(Mymonth < 10) {Mymonth= "0" +Mymonth;} if(Myweekday < 10) {Myweekday= "0" +Myweekday;} return(myyear+ "-" +mymonth + "-" +myweekday); }//get the number of days in a monthfunctionGetmonthdays (mymonth) {varMonthstartdate =NewDate (Nowyear, Mymonth, 1); varMonthenddate =NewDate (nowyear, Mymonth + 1, 1); varDays = (monthenddate-monthstartdate)/(1000 * 60 * 60 * 24);returnDays ;}//get the start month of the quarterfunctionGetquarterstartmonth () {varQuarterstartmonth = 0; if(nowmonth<3) {Quarterstartmonth= 0; } if(2<nowmonth && nowmonth<6) {Quarterstartmonth= 3; } if(5<nowmonth && nowmonth<9) {Quarterstartmonth= 6; } if(nowmonth>8) {Quarterstartmonth= 9; } returnQuarterstartmonth;}//get the start date for this weekfunctiongetweekstartdate () {varWeekstartdate =NewDate (Nowyear, Nowmonth, Nowday-Nowdayofweek); returnformatdate (weekstartdate);}//get this week's stop datefunctiongetweekenddate () {varWeekenddate =NewDate (Nowyear, Nowmonth, Nowday + (6-Nowdayofweek)); returnformatdate (weekenddate);}//get the start date for this monthfunctiongetmonthstartdate () {varMonthstartdate =NewDate (Nowyear, Nowmonth, 1); returnformatdate (monthstartdate);}//get the stop date for this monthfunctiongetmonthenddate () {varMonthenddate =NewDate (Nowyear, Nowmonth, Getmonthdays (Nowmonth));returnformatdate (monthenddate);}//get started last monthfunctiongetlastmonthstartdate () {varLastmonthstartdate =NewDate (Nowyear, Lastmonth, 1); returnformatdate (lastmonthstartdate);}//get last month stop timefunctiongetlastmonthenddate () {varLastmonthenddate =NewDate (Nowyear, Lastmonth, Getmonthdays (Lastmonth));returnformatdate (lastmonthenddate);}//get the start date for the quarterfunctiongetquarterstartdate () {varQuarterstartdate =NewDate (Nowyear, Getquarterstartmonth (), 1); returnformatdate (quarterstartdate);}//or the stop date for this quarterfunctiongetquarterenddate () {varQuarterendmonth = Getquarterstartmonth () + 2; varQuarterstartdate =NewDate (Nowyear, Quarterendmonth, Getmonthdays (Quarterendmonth));returnformatdate (quarterstartdate);} 

JS get this week, this quarter, this month, the last month's start date, stop date

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.