JS gets this week, this month, the start date and end date for this quarter

Source: Internet
Author: User

1<script>2 varnow =NewDate ();//Current Date3 varNowdayofweek = Now.getday ();//the day of the week today4 varNowday = Now.getdate ();//Current Day5 varNowmonth = Now.getmonth ();//Current Month6 varNowyear = Now.getyear ();//Current year7Nowyear + = (Nowyear < -) ?1900:0;//     8     9 //formatted Date: YYYY-MM-DDTen function FormatDate (date) { One     varMyyear =date.getfullyear ();  A     varMymonth = Date.getmonth () +1;  -     varMyweekday =date.getdate ();  -           the     if(Mymonth <Ten){      -Mymonth ="0"+Mymonth;  -     }       -     if(Myweekday <Ten){      +Myweekday ="0"+Myweekday;  -     }      +     return(myyear+"-"+mymonth +"-"+myweekday);  A }       at      - //get the number of days in a month - function Getmonthdays (mymonth) { -     varMonthstartdate =NewDate (Nowyear, Mymonth,1);  -     varMonthenddate =NewDate (nowyear, Mymonth +1,1);  -     varDays = (monthenddate-monthstartdate)/( +* -* -* -);  in     returnDays ;  - }      to      + //get the start month of the quarter - function Getquarterstartmonth () { the     varQuarterstartmonth =0;  *     if(nowmonth<3){      $Quarterstartmonth =0; Panax Notoginseng     }      -     if(2<nowmonth && nowmonth<6){      theQuarterstartmonth =3;  +     }      A     if(5<nowmonth && nowmonth<9){      theQuarterstartmonth =6;  +     }      -     if(nowmonth>8){      $Quarterstartmonth =9;  $     }      -     returnQuarterstartmonth;  - }      the      - //get the start date for this weekWuyi function Getweekstartdate () { the     varWeekstartdate =NewDate (Nowyear, Nowmonth, Nowday-Nowdayofweek);  -     returnformatdate (weekstartdate);  Wu }       -      About //Get the end date for this week $ function Getweekenddate () { -     varWeekenddate =NewDate (Nowyear, Nowmonth, Nowday + (6-Nowdayofweek));  -     returnformatdate (weekenddate);  - }       A      + //get the start date for this month the function Getmonthstartdate () { -     varMonthstartdate =NewDate (Nowyear, Nowmonth,1);  $     returnformatdate (monthstartdate);  the }      the      the //Get the end date for this month the function Getmonthenddate () { -     varMonthenddate =NewDate (Nowyear, Nowmonth, Getmonthdays (Nowmonth));  in     returnformatdate (monthenddate);  the }      the      About //get the start date for the quarter the function Getquarterstartdate () { the           the     varQuarterstartdate =NewDate (Nowyear, Getquarterstartmonth (),1);  +     returnformatdate (quarterstartdate);  - }      the     Bayi //or the end date of the quarter the function Getquarterenddate () { the     varQuarterendmonth = Getquarterstartmonth () +2;  -     varQuarterstartdate =NewDate (Nowyear, Quarterendmonth, Getmonthdays (Quarterendmonth));  -     returnformatdate (quarterstartdate);  the }      the      the alert (Getquarterenddate ());  the</script>

JS gets this week, this month, the start date and end date for this quarter

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.