JS to display data for the next day

Source: Internet
Author: User

1. (Background: In the past, when performing a system query, you must display the system's current and next day. The current time is easy to write, but not the next day, the following is the one you tried to write .)
Function tomorrow (){
VaR date = new date ();
VaR year = date. getyear (); // obtain the current year command
VaR month = date. getmonth () 1;
VaR day = date. getdate ();
VaR datestr = NULL;
If (Year % 4 = 0 & amp; Year % 100! = 0 | year % 400 = 0) {// This is a leap year.
If (month = 1 | month = 3 | month = 5 | month = 7 | month = 8 | month = 10 ){
If (Day = 31 ){
Month = Month 1;
If (month <10) {month = '0' month ;}
Datestr = year "-" month "-" 01 ";
} Else if (day! = 31 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
} Else if (month = 4 | month = 6 | month = 9 | month = 11 ){
If (Day = 30 ){
Month = Month 1;
If (month <10) {month = '0' month ;}
Datestr = year "-" month "-" 01 ";
} Else if (day! = 30 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
} Else if (month = 12 ){
If (Day = 31) {month = "01"; datestr = year 1 "-" month "-" 01 ";}
Else if (day! = 31 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
} Else if (month = 2 ){
If (Day = 29) {month = "03"; datestr = year "-" month "-" 01 ";}
Else if (day! = 29 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
}
} Else {// non-leap year
If (month = 1 | month = 3 | month = 5 | month = 7 | month = 8 | month = 10 ){
If (Day = 31 ){
Month = Month 1;
If (month <10) {month = '0' month ;}
Datestr = year "-" month "-" 01 ";
} Else if (day! = 31 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
} Else if (month = 4 | month = 6 | month = 9 | month = 11 ){
If (Day = 30 ){
Month = Month 1;
If (month <10) {month = '0' month ;}
Datestr = year "-" month "-" 01 ";
} Else if (day! = 30 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
} Else if (month = 12 ){
If (Day = 31) {month = "01"; datestr = year 1 "-" month "-" 01 ";}
Else if (day! = 31 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
} Else if (month = 2 ){
If (Day = 28) {month = "03"; datestr = year "-" month "-" 01 ";}
Else if (day! = 28 ){
Day = Day 1;
If (month <10) {month = '0' month ;}
If (day <10) {day = '0' day ;}
Datestr = year "-" month "-" Day ;}
}
}
Alert (datestr); // added to view the result
}

2. Self-written features are prone to errors. by calling the built-in functions of JS, the auto-increment of the generated objects can well control the generation of 2008-10-32, undefined, and null.
Function nextdate (){
VaR date = new date ();
VaR B = date. getdate ();
B + = 1;
Date. setdate (B );
VaR year = date. getyear (); // obtain the current year command
VaR month = date. getmonth () + 1;
VaR day = date. getdate ();
If (month <10) {month = '0' + month ;}
If (day <10) {day = '0' + day ;}
VaR datestr = year + "-" + month + "-" + Day;
Alert (datestr );
}

 

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.