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

Source: Internet
Author: User

/** * Get the start date, end date of 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 (); //formatted 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); }    //TodayvarGetcurrentdate =NewDate (Nowyear, Nowmonth, nowday);varGetcurrentdate =formatdate (getcurrentdate)//YesterdayvarGetyesterdaydate =NewDate (Nowyear, Nowmonth, nowDay-1);varGetyesterdaydate =formatdate (getyesterdaydate); //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 the end date for this weekfunctiongetweekenddate () {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 end date for this monthfunctiongetmonthenddate () {varMonthenddate =NewDate (Nowyear, Nowmonth, Getmonthdays (Nowmonth)); returnformatdate (monthenddate); }   //get start time last monthfunctiongetlastmonthstartdate () {varLastmonthstartdate =NewDate (Nowyear, Lastmonth, 1); returnformatdate (lastmonthstartdate); }//get last month end 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 end date of the quarterfunctiongetquarterenddate () {varQuarterendmonth = Getquarterstartmonth () + 2; varQuarterstartdate =NewDate (Nowyear, Quarterendmonth, Getmonthdays (Quarterendmonth)); returnformatdate (quarterstartdate); }

JS Get the start date, end date

for this week, this quarter, this month, the last month

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.