JS get last one months, next one months

Source: Internet
Author: User

/** * Get last one months * * @date format is YYYY-MM-DD date, such as: 2014-01-25 */function Getpremonth (d            ATE) {var arr = date.split ('-'); var year = arr[0]; Gets the year of the current date var month = arr[1]; Gets the month of the current date var day = arr[2];            Gets the day of the current date var days = new Date (year, month, 0); Days = Days.getdate ();            Gets the number of days of the month in the current date var year2 = year;            var month2 = parseint (month)-1;                if (month2 = = 0) {year2 = parseint (year2)-1;            Month2 = 12;            } var day2 = day;            var days2 = new Date (year2, month2, 0);            Days2 = Days2.getdate ();            if (Day2 > Days2) {day2 = Days2; } if (Month2<Ten) {month2= ' 0 '+ month2; } var T2= Year2+ '-' + month2 + '-' + day2;        return T2; /** * Get Next one months * * @date format is YYYY-MM-DD date, such as: 2014-01-25 */FU Nction Getnextmonth (date) {var arr= Date.split ('-'); var year= arr[0];//Gets the year of the current date var month= arr[1];//Get the Month Var day for the current date= arr[2];//Gets the day of the current date var days= newDate (year, month, 0); days= Days.getdate ();//Gets the number of months in the current date var year2= year; var month2= parseint (month)+ 1; if (Month2== {year2= parseint (year2)+ 1; Month2= 1; } var day2= day; var days2= newDate (year2, month2, 0); Days2= Days2.getdate (); if (day2>days2)            {day2 = Days2; } if (Month2<Ten) {month2= ' 0 '+ month2; } var T2= Year2+ '-' + month2 + '-' + day2;        return T2;        }//Test//alert (Getpremonth ("2014-01-25")); Alert (Getnextmonth ("2014-12-25"));

Source: http://www.cnblogs.com/love540376/p/4582443.html

 /** * Get last one months * * @date format is YYYY-MM-DD date, such as: 2014-01-25 */function Getpremonth (date)            {var arr = date.split ('-'); var year = arr[0]; Gets the year of the current date var month = arr[1]; Gets the month of the current date var day = arr[2];            Gets the day of the current date var days = new Date (year, month, 0); Days = Days.getdate ();            Gets the number of days of the month in the current date var year2 = year;            var month2 = parseint (month)-1;                if (month2 = = 0) {year2 = parseint (year2)-1;            Month2 = 12;            } var day2 = day;            var days2 = new Date (year2, month2, 0);            Days2 = Days2.getdate ();            if (Day2 > Days2) {day2 = Days2;            } if (Month2 <) {month2 = ' 0 ' + month2;            } var t2 = year2 + '-' + month2 + '-' + day2;        return T2; }/** * Get next one months * * @date format yyYy-mm-dd date, such as: 2014-01-25 */function Getnextmonth (date) {var arr = date.split ('-'); var year = arr[0]; Gets the year of the current date var month = arr[1]; Gets the month of the current date var day = arr[2];            Gets the day of the current date var days = new Date (year, month, 0); Days = Days.getdate ();            Gets the number of days of the month in the current date var year2 = year;            var month2 = parseint (month) + 1;                if (month2 = =) {year2 = parseint (year2) + 1;            Month2 = 1;            } var day2 = day;            var days2 = new Date (year2, month2, 0);            Days2 = Days2.getdate ();            if (Day2 > Days2) {day2 = Days2;            } if (Month2 <) {month2 = ' 0 ' + month2;            } var t2 = year2 + '-' + month2 + '-' + day2;        return T2;        }//Test//alert (Getpremonth ("2014-01-25")); Alert (Getnextmonth ("2014-12-25 ")); 

JS get last one month, next 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.