JS how to get the current one month, the next one months and the month contains the days

Source: Internet
Author: User

In a data report query, it is often necessary to set the date range of the query, such as querying the month of 2018-02-01 to 2018-02-28 data, when you need to provide a quick month query button:
Such as:

The general date and month day between the "-" or "/" and so on to split open, simple judgment of the current month processing can be. In addition, how to get the maximum number of days for the selected month is key, which can be handled with the help of the JS self-contained date function, the key is to navigate to the last day of the selected month

The key code is as follows:

function Changemonth(type){        //Gets the date in the current input box        varS_date= $("Input[name= ' s_date ')").Val();        varE_date= $("Input[name= ' e_date ')").Val();        varArr= s_date.Split("-");        varYear= parseint(arr[0]),Month= parseint(arr[1]),Day= parseint(arr[2]);        varYear2=Year,Month2,Day2;        //Take one months        if(Type== ' pre '){Month2=Month- 1;            if(Month2== 0){   //If current is JanuaryMonth2=  A;Year2=Year- 1;            }        } Else {Month2=Month+ 1;            if(Month2==  -){Month2= 1;Year2=Year+ 1;            }        }        //Output The first day of the selected month        varStart=Year2+ "-" +Month2+ "-" + "1";        //Get current        varDate= New Date(start);        varYear= Date.getFullYear();        varMonth= Date.GetMonth()+1;        varD= New Date(Year,Month,0);   //The day before the next one months        varEnd=Year2+ "-" +Month2+ "-" + D.getDate();        Console.Log(Start,End;        //Set the value of the current time input        $("Input[name= ' s_date ')").Val(start);        $("Input[name= ' e_date ')").Val(end);    }

JS how to get the current one month, the next one months and the month contains the days

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.