JS Get Date

Source: Internet
Author: User

 var now = new Date ();                     //Current date     var Nowdayofweek = Now.getday ();         //today's Day of the week     var NowDay = Now.getDate ();              //Current Day     var Nowmonth = Now.getmonth ();           //Current month     var nowYear = Now.getyear ();             //Current year     nowyear + = (Nowyear < 2000)? 1900:0;  //     var lastmonthdate = new Date ();  //Last month date     lastmonthdate.setdate (1);     lastmonthdate.setmonth ( Lastmonthdate.getmonth ()-1);     var lastyear = Lastmonthdate.getyear ();   &nbsP; var lastmonth = Lastmonthdate.getmonth ();      //formatted date:yyyy-mm-dd     function formatdate (date) {        var myyear = Date.getfullyear ();         var mymonth = Date.getmonth () +1;         var myweekday = date.getdate ();          if (Mymonth <) {            mymonth = "0" + mymonth;        }         if (Myweekday <) {            myweekday = "0" + myweekday;        }         Return (myyear+ "-" +mymonth + "-" + myweekday);     }     //get the number of days in a month      function Getmonthdays (mymonth) {        var monthStartDate = new Date (Nowyear, Mymonth, 1);         var monthenddate = new Date (nowYear, MyMonth + 1, 1);         var   days   =    (monthEndDate   -  monthstartdate)/(  *   60   *   60    *   24);         return   days;     }     //get the start of the quarter     function GetQuarterStartMonth () {         var Quarterstartmonth = 0;         if (nowmonth<3) {             Quarterstartmonth = 0;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSp; if (2<6) {            quarterstartmonth = 3;        }        if (5<9) {             quarterstartmonth = 6;         }        if (nowMonth>8) {             quarterstartmonth = 9;         }        return quarterstartmonth;     }     //today     var getcurrentdate = new Date (NowYear, NowMonth, Nowday);     var getcurrentdate  = formatdate (getcurrentdate)       //yesterday     var getyesterdaydate = new Date (nowyear, Nowmonth, nowDay-1);   &nbSp; var getyesterdaydate =  formatdate (getyesterdaydate);      //get start date of the week     var getweekstartdate = new Date (nowyear, Nowmonth, Nowday-nowdayofweek);    & Nbsp;var getweekstartdate =  formatdate (getweekstartdate);     //get this week's end date      var getweekenddate = new Date (nowyear, Nowmonth, Nowday + (6-nowdayofweek));     var get Weekenddate =  formatdate (getweekenddate);       //get last week's start date      var getupweekstartdate = new Date (nowyear, Nowmonth, nowday-nowdayofweek-7);     var Getupweekstartdate =  formatdate (getupweekstartdate);      //get last week's end date      var getupweekenddate = new Date (nowyear, Nowmonth, Nowday + (6-nowdayofweek-7));     va R getupweekenddate =  formatdate (getupweekenddate);      //Get start date of this month     var getmonthstartdate = new Date (Nowyear, Nowmonth, 1);     var getmonthstartdate =  formatdate (getmonthstartdate);      //get end date for this month      var getmonthenddate = new Date (nowyear, Nowmonth, Getmonthdays (nowmonth));     var getmonthenddate =  formatdate (getmonthenddate);      //get last month start time      var getlastmonthstartdate = new Date (Nowyear, Lastmonth, 1);     var Getlastmonthstartdate = FormatDate (getlastmonthstartdate);      //get last month end time      var getlastmonthenddate = new Date (nowyear, Lastmonth, Getmonthdays (lastmonth));     var getlastmonthenddate = formatdate (getlastmonthenddate);

JS Get 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.