Calculation of the day of the week (if statement)

Source: Internet
Author: User

public boolean chackyear (int str) {//Judgment Common year, leap year

Boolean q = str% 4 = = 0;

Boolean w = str% 100 = = 0;

Boolean e = str% 400 = = 0;

Boolean r = False;

if (q) {

if (w = = False | | e) {

R = True;

}

}

return R;

}

Public String Chackday (int year, int month, Int. day) {

int c = code for 0;//Month

int s = 0;//code for 21st century years

int B = 20;//years

int y3 = The latter two digits of 0;//year

int i = 0;//year array subscript i

String y = string.valueof (year);

String y1 = y.substring (2, 4);//extract year after two

int y4 = Integer.parseint (y1);//Convert year format

String y2 = y.substring (0, 2);//extract the first two digits of the year

Y3 = Integer.parseint (y2);//Convert year first two-bit format

Int[] k = {5, 3, 1, 0};//year code array

Int[] L = {1, 3, 5, 0};//year code array

if (Y3 > B) {//judgment: compare with 21st century

i = (y3-b)% 4-1;

s = ((Y4/4) + y4)% 7 + k[i];

} else if (Y3 < b) {

i = (b-y3)% 4-1;

s = ((Y4/4) + y4)% 7 + l[i];

} else {

i = 3;

s = ((Y4/4) + y4)% 7 + l[i];

}

r-2| | +5 18 1777

//

R+3 19 1888

R+1 20 1999

R 21 2010

if (chackyear (year) = = False) {//Judgment Common year, leap year

if (month = = 5) {//month code

c = 0;

} else if (month = = 8) {

c = 1;

} else if (month = = 2 | month = = 3 | | month = = 11) {

c = 2;

} else if (month = = 6) {

c = 3;

} else if (month = = | | month = = 9) {

c = 4;

} else if (month = = 4 | | month = = 7) {

c = 5;

} else if (month = = 1 | | month = = 10) {

c = 6;

}

} else {

if (month = = 5) {

c = 0;

} else if (month = = 2 | | month = = 8) {

c = 1;

} else if (month = = 3 | | month = = 11) {

c = 2;

} else if (month = = 6) {

c = 3;

} else if (month = = | | month = = 9) {

c = 4;

} else if (month = = 1 | | month = = 4 | | month = = 7) {

c = 5;

} else if (month = = 1 | | month = = 10) {

c = 6;

}

}

int r = (s + C + day)% 7;//Week calculation

String result = "";//Initialize variable

Switch (r) {//Judge Day of the week

Case 0:

result = "Sunday";

Break

Case 1:

result = "Monday";

Break

Case 2:

result = "Tuesday";

Break

Case 3:

result = "Wednesday";

Break

Case 4:

result = "Thursday";

Break

Case 5:

result = "Friday";

Break

Case 6:

result = "Saturday";

Break

Default

Break

}

return result;

}

Calculation of the day of the week (if statement)

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.