首页 > 编程知识 正文

万年历查询节日程序代码,电脑数码万年历

时间:2023-05-04 15:00:49 阅读:116078 作者:4373

public class Demo03 {
//获取每年首日周几
public static int kalendar(int year, int month) {
Calendar calendar = Calendar.getInstance();
calendar.set(year,0,1,0,0,0);
Date date = calendar.getTime();
long atYear = date.getTime();
int weekday =((year - 1970)*365+leapyear(year,month) + 4) % 7;
return weekday;

}//获取闰年年数public static int leapyear(int year, int month) {int count = 0 ;for(int i = 1970; i < year; i++ ) {if ( (i % 4 == 0 && i % 100 !=0) || i % 400 == 0) {count += 1;}}return count;}//打印每月日期public static void show(int year, int month) {int m = kalendar(year,month);if ( (year % 4 == 0 && year % 100 !=0) || year % 400 == 0) {switch(month) {case 1:for (int j = 0;j < m ; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if((m-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 2:for (int j = 0;j <(31+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 29; i++) {if(((31+m-1+i)) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 3:for (int j = 0;j <(60+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((60+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 4:for (int j = 0;j <(91+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((91+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 5:for (int j = 0;j <(121+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((121+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {for (int j = 0;j <(121+m)%7; j++) {System.out.print("t");}System.out.print(i+"t");}}break;case 6:for (int j = 0;j <(152+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((152+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 7:for (int j = 0;j <(182+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((182+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 8:for (int j = 0;j <(213+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((213+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 9:for (int j = 0;j <(244+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((244+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 10:for (int j = 0;j <(274+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((274+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 11:for (int j = 0;j <(305+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((305+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 12:for (int j = 0;j <(335+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((335+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;}}else {switch(month) {case 1:for (int j = 0;j < m-1; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if((m-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 2:for (int j = 0;j <(31+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 28; i++) {if(((31+m-1+i)) % 7 == 0 ) {System.out.print(i+"t");System.out.println();}else {System.out.print(i+"t");}}break;case 3:for (int j = 0;j <(59+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((59+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 4:for (int j = 0;j <(90+m)%7-1; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((90+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 5:for (int j = 0;j <(120+m)%7-1; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((120+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 6:for (int j = 0;j <(151+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((151+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 7:for (int j = 0;j <(181+m-1)%7; j++) {System.out.print(" t");}for (int i = 1; i <= 31; i++) {if(((181+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 8:for (int j = 0;j <(212+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((212+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 9:for (int j = 0;j <(243+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((243+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 10:for (int j = 0;j <(273+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((273+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 11:for (int j = 0;j <(304+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 30; i++) {if(((304+m)-1+i) % 7 == 0) {System.out.println(i);}else {System.out.print(i+"t");}}break;case 12:for (int j = 0;j <(334+m-1)%7; j++) {System.out.print(" "+"t");}for (int i = 1; i <= 31; i++) {if(((334+m)-1+i) % 7 == 0 ) {System.out.println(i);}else {System.out.print(i+"t");}}break;}}}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。