‘壹’ java日历查询程序(万年历)
花了半个小时写了一个望采纳给好评。
import java.util.Scanner;
public class PrintCalendar {
/** Main method */
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user to enter year
System.out.print("Enter full year (e.g., 2001): ");
int year = input.nextInt();
// Prompt the user to enter month
System.out.print("Enter month in number between 1 and 12: ");
int month = input.nextInt();
// Print calendar for the month of the year
printMonth(year, month);
}
/** Print the calendar for a month in a year */
public static void printMonth(int year, int month) {
// Print the headings of the calendar
printMonthTitle(year, month);
// Print the body of the calendar
printMonthBody(year, month);
}
/** Print the month title, e.g., May, 1999 */
public static void printMonthTitle(int year, int month) {
System.out.println(" " + getMonthName(month)
+ " " + year);
System.out.println("-----------------------------");
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
}
/** Get the English name for the month */
public static String getMonthName(int month) {
String monthName = "";
switch (month) {
case 1: monthName = "January"; break;
case 2: monthName = "February"; break;
case 3: monthName = "March"; break;
case 4: monthName = "April"; break;
case 5: monthName = "May"; break;
case 6: monthName = "June"; break;
case 7: monthName = "July"; break;
case 8: monthName = "August"; break;
case 9: monthName = "September"; break;
case 10: monthName = "October"; break;
case 11: monthName = "November"; break;
case 12: monthName = "December";
}
return monthName;
}
/** Print month body */
public static void printMonthBody(int year, int month) {
// Get start day of the week for the first date in the month
int startDay = getStartDay(year, month);
// Get number of days in the month
int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);
// Pad space before the first day of the month
int i = 0;
for (i = 0; i < startDay; i++)
System.out.print(" ");
for (i = 1; i <= numberOfDaysInMonth; i++) {
System.out.printf("%4d", i);
if ((i + startDay) % 7 == 0)
System.out.println();
}
System.out.println();
}
/** Get the start day of month/1/year */
public static int getStartDay(int year, int month) {
final int START_DAY_FOR_JAN_1_1800 = 3;
// Get total number of days from 1/1/1800 to month/1/year
int totalNumberOfDays = getTotalNumberOfDays(year, month);
// Return the start day for month/1/year
return (totalNumberOfDays + START_DAY_FOR_JAN_1_1800) % 7;
}
/** Get the total number of days since January 1, 1800 */
public static int getTotalNumberOfDays(int year, int month) {
int total = 0;
// Get the total days from 1800 to 1/1/year
for (int i = 1800; i < year; i++)
if (isLeapYear(i))
total = total + 366;
else
total = total + 365;
// Add days from Jan to the month prior to the calendar month
for (int i = 1; i < month; i++)
total = total + getNumberOfDaysInMonth(year, i);
return total;
}
/** Get the number of days in a month */
public static int getNumberOfDaysInMonth(int year, int month) {
if (month == 1 || month == 3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12)
return 31;
if (month == 4 || month == 6 || month == 9 || month == 11)
return 30;
if (month == 2) return isLeapYear(year) ? 29 : 28;
return 0; // If month is incorrect
}
/** Determine if it is a leap year */
public static boolean isLeapYear(int year) {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
}
‘贰’ 怎么用JAVA编写万年历!
/*
题目:输出任意年份任意月份的日历表(公元后)
思路:
1.已知1年1月1日是星期日,1%7=1对应的是星期日,2%7=2对应的是星期一,以此类推;
2.计算当年以前所有天数+当年当月1号之前所有天数;
a.年份分平年闰年,平年365天,闰年366天;
b.闰年的判断方法year%400==0||(year%100!=0&&year%4==0)若为真,则为闰年否则为平年;
c.定义平年/闰年数组,包含各月天数;
d.遍历数组求和,计算当年当月前总天数;
e.当年以前所有天数+当年当月前总天数+1即为1年1月1日到当年当月1日的总天数;
3.总天数对7取模,根据结果判断当月1号是星期几,输出空白区域;
4.输出当月日历表,逢星期六换行
*/
importjava.util.Scanner;
classFindMonthList{
publicstaticvoidmain(String[]args){
Scannersc=newScanner(System.in);
System.out.println("请输入年份:");
intyear=sc.nextInt();//年份
if(year<1){//判断非法输入年份
System.out.println("输入错误!");
return;
}
System.out.println("请输入月份:");
intmonth=sc.nextInt();//月份
if(month<1||month>12){//判断非法输入月份
System.out.println("输入错误!");
return;
}
//输出表头
System.out.println("-------"+year+"年"+month+"月"+"-------");
System.out.println();
System.out.println("日一二三四五六");
//计算当前年份以前所有天数beforeYearTotalDay;每4年一个闰年,闰年366天,平年365天
intbeforeYearTotalDay=((year-1)/4*366)+(year-1-((year-1)/4))*365;
int[]arrLeapYear={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年各月天数int数组
int[]arrNormalYear={0,31,28,31,30,31,30,31,31,30,31,30,31};//平年各月天数int数组
intbeforeMonthTotalDay=0;//定义本年当月之前月份的总天数
if(year%400==0||(year%100!=0&&year%4==0)){//判断当前年份是否是闰年
for(inti=0;i<month;i++){//for循环计算当月之前总天数
//计算当前月份之前的所有天数
beforeMonthTotalDay=beforeMonthTotalDay+arrLeapYear[i];
}
//判断当月1日是星期几
inttotalDay=beforeYearTotalDay+beforeMonthTotalDay+1;
intweek=totalDay%7;//已知1年1月1日是星期日,即模7得1对应的是星期日
for(inti=0;i<(week-1+7)%7;i++){//如果写成i<(week-1)会出现i<-1的情况
System.out.print("");//输出开头空白
}
for(inti=1;i<=arrLeapYear[month];i++){//for循环输出各月天数
System.out.print(i+"");
if(i<10){//小于10的数补一个空格,以便打印整齐
System.out.print("");
}
if(i%7==((7-(week-1))%7)||i==arrLeapYear[month]){//每逢星期六/尾数换行
System.out.println();
}
}
}else{//不是闰年就是平年
for(inti=0;i<month;i++){//for循环计算出当月之前月份总天数
beforeMonthTotalDay=beforeMonthTotalDay+arrNormalYear[i];
}
//判断当月1日是星期几
inttotalDay=beforeYearTotalDay+beforeMonthTotalDay+1;
intweek=totalDay%7;//已知1年1月1日是星期日,即模7得1对应的是星期日
for(inti=0;i<(week-1+7)%7;i++){//如果写成i<(week-1)会出现i<-1的情况
System.out.print("");//输出开头空白
}
for(inti=1;i<=arrNormalYear[month];i++){//for循环输出各月天数
System.out.print(i+"");
if(i<10){//小于10的数补一个空格,以便打印整齐
System.out.print("");
}
if(i%7==((7-(week-1))%7)||i==arrNormalYear[month]){//每逢星期六/尾数换行
System.out.println();
}
}
}
}
}
效果:
‘叁’ 万年历JAVA程序上机
我这里两个类,你跑起来看看,一个是计算农历的,一个是拿来显示的。
import java.util.*;
/**
* 农历计算
*
* @author xysource
*
*/
public class LauarUtil
{
private static String[] daySTrPreArray = { "初", "十", "廿", "卅", " " };
/**
* 月份
*/
private static String[] dayStrArray = { "", "一", "二", "三", "四", "五", "六",
"七", "八", "九", "十", "十一", "十二" };
// private static String[] weekStrArray = { "", "日", "一", "二", "三", "四",
// "五", "六" };
final static long[] lunarInfo = new long[] { 0x04bd8, 0x04ae0, 0x0a570,
0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,
0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50,
0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566,
0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,
0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4,
0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550,
0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950,
0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260,
0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0,
0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40,
0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3,
0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960,
0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0,
0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9,
0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0,
0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65,
0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0,
0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2,
0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };
final public static int lYearDays(int y)// ====== 传回农历 y年的总天数
{
int i, sum = 348;
for (i = 0x8000; i > 0x8; i >>= 1)
{
if ((lunarInfo[y - 1900] & i) != 0)
sum += 1;
}
return (sum + leapDays(y));
}
final public static int leapDays(int y)// ====== 传回农历 y年闰月的天数
{
if (leapMonth(y) != 0)
{
if ((lunarInfo[y - 1900] & 0x10000) != 0)
return 30;
else
return 29;
}
else
return 0;
}
final public static int leapMonth(int y)// ====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
{
return (int) (lunarInfo[y - 1900] & 0xf);
}
final public static int monthDays(int y, int m)// ====== 传回农历 y年m月的总天数
{
if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
return 29;
else
return 30;
}
final public static String AnimalsYear(int y)// ====== 传回农历 y年的生肖
{
final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇",
"马", "羊", "猴", "鸡", "狗", "猪" };
return Animals[(y - 4) % 12];
}
final public static String cyclicalm(int num)// ====== 传入 月日的offset 传回干支,
// 0=甲子
{
final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚",
"辛", "壬", "癸" };
final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午",
"未", "申", "酉", "戌", "亥" };
return (Gan[num % 10] + Zhi[num % 12]);
}
final public static String cyclical(int y)// ====== 传入 offset 传回干支, 0=甲子
{
int num = y - 1900 + 36;
return (cyclicalm(num));
}
final public long[] Lunar(int y, int m)// 传出农历.year0 .month1 .day2
// .yearCyl3
// .monCyl4
// .dayCyl5 .isLeap6
{
final int[] year20 = new int[] { 1, 4, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
final int[] year19 = new int[] { 0, 3, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
final int[] year2000 = new int[] { 0, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
Date baseDate = new Date(1900, 1, 31);
Date objDate = new Date(y, m, 1);
long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;
if (y < 2000)
offset += year19[m - 1];
if (y > 2000)
offset += year20[m - 1];
if (y == 2000)
offset += year2000[m - 1];
nongDate[5] = offset + 40;
nongDate[4] = 14;
for (i = 1900; i < 2050 && offset > 0; i++)
{
temp = lYearDays(i);
offset -= temp;
nongDate[4] += 12;
}
if (offset < 0)
{
offset += temp;
i--;
nongDate[4] -= 12;
}
nongDate[0] = i;
nongDate[3] = i - 1864;
leap = leapMonth(i); // 闰哪个月
nongDate[6] = 0;
for (i = 1; i < 13 && offset > 0; i++)
{
// 闰月
if (leap > 0 && i == (leap + 1) && nongDate[6] == 0)
{
--i;
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
}
else
{
temp = monthDays((int) nongDate[0], i);
}
// 解除闰月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
offset -= temp;
if (nongDate[6] == 0)
nongDate[4]++;
}
if (offset == 0 && leap > 0 && i == leap + 1)
{
if (nongDate[6] == 1)
{
nongDate[6] = 0;
}
else
{
nongDate[6] = 1;
--i;
--nongDate[4];
}
}
if (offset < 0)
{
offset += temp;
--i;
--nongDate[4];
}
nongDate[1] = i;
nongDate[2] = offset + 1;
return nongDate;
}
final public static long[] calElement(int y, int m, int d)
// 传出y年m月d日对应的农历.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6
{
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
Date baseDate = new Date(0, 0, 31);
Date objDate = new Date(y - 1900, m - 1, d);
long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;
nongDate[5] = offset + 40;
nongDate[4] = 14;
for (i = 1900; i < 2050 && offset > 0; i++)
{
temp = lYearDays(i);
offset -= temp;
nongDate[4] += 12;
}
if (offset < 0)
{
offset += temp;
i--;
nongDate[4] -= 12;
}
nongDate[0] = i;
nongDate[3] = i - 1864;
leap = leapMonth(i); // 闰哪个月
nongDate[6] = 0;
for (i = 1; i < 13 && offset > 0; i++)
{
// 闰月
if (leap > 0 && i == (leap + 1) && nongDate[6] == 0)
{
--i;
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
}
else
{
temp = monthDays((int) nongDate[0], i);
}
// 解除闰月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
offset -= temp;
if (nongDate[6] == 0)
nongDate[4]++;
}
if (offset == 0 && leap > 0 && i == leap + 1)
{
if (nongDate[6] == 1)
{
nongDate[6] = 0;
}
else
{
nongDate[6] = 1;
--i;
--nongDate[4];
}
}
if (offset < 0)
{
offset += temp;
--i;
--nongDate[4];
}
nongDate[1] = i;
nongDate[2] = offset + 1;
return nongDate;
}
public static String getchina(int day)
{
if (day == 10)
return "初十";
if (day == 20)
return "二十";
if (day == 30)
return "三十";
String a = daySTrPreArray[(int) ((day) / 10)];
//System.out.println(a);
a += dayStrArray[(int) (day % 10)];
return a;
}
public static String getLauar(Calendar cld)
{
int year = cld.get(Calendar.YEAR);
int month = cld.get(Calendar.MONTH) + 1;
int day = cld.get(Calendar.DAY_OF_MONTH);
long[] lauarStrArray = calElement(year, month, day);
String monthStr = dayStrArray[(int) (lauarStrArray[1])];
return monthStr + "月" + getchina((int) (lauarStrArray[2]));//AnimalsYear(1989)+"年农历" +
}
public static void main(String[] args)
{
Calendar cld = Calendar.getInstance();
// for (int i = 0; i < 145; i++) {
System.out.println(getLauar(cld));
// cld.add(Calendar.DAY_OF_MONTH, 1);
// }
}
}
‘肆’ 用JAVA编写一个万年历
import java.io.*;
class putout{
public void putout(int f,int x,int y){
int i;
int a[]= new int[40];
System.out.println(" 日 一 二 三 四 五 六 "+" "+f+"月");
for (i=0;i<x;i++)
{System.out.print(" "); }
for(i=x;i<x+y;i++)
a[i]=i-x+1;
for(i=x;i<x+y;i++)
{
if ((i%7==0)&&(i>0))
System.out.print("\n");
if (a[i]<10)
System.out.print(" "+a[i]);
else System.out.print(" "+a[i]);
}
System.out.println("\n");
}
}
class st{
public static void main(String args[])throws IOException{
putout p=new putout();
int year,mouth,y=1,t,i;
InputStreamReader ir;
BufferedReader in;
ir=new InputStreamReader(System.in);
in=new BufferedReader(ir);
System.out.print("请输入一个年份:");
String s=in.readLine();
year=Integer.parseInt(s);
if((year%4==0 && year%100!=0)||(year%400==0))
mouth=1;
else
mouth=0;
y=year;
for(i=1;i<year;i++)
{if((i%4==0 && i%100!=0)||(i%400==0))
y++;}
y=y%7;
for(i=1;i<13;i++){
switch(i){
case 1: {p.putout(1,y,31);y=(y+31)%7;break;}
case 2: {p.putout(2,y,28+mouth);y=(y+28+mouth)%7;break;}
case 3: {p.putout(3,y,31);y=(y+31)%7;break;}
case 4: {p.putout(4,y,30);y=(y+30)%7;break;}
case 5: {p.putout(5,y,31);y=(y+31)%7;break;}
case 6: {p.putout(6,y,30);y=(y+30)%7;break;}
case 7: {p.putout(7,y,31);y=(y+31)%7;break;}
case 8: {p.putout(8,y,31);y=(y+31)%7;break;}
case 9: {p.putout(9,y,30);y=(y+30)%7;break;}
case 10: {p.putout(10,y,31);y=(y+31)%7;break;}
case 11: {p.putout(11,y,30);y=(y+30)%7;break;}
case 12: {p.putout(12,y,31);y=(y+31)%7;break;}
}
}
}
}
‘伍’ 编写 万年历java代码例如1900年一月一日是星期一。
importjava.util.Calendar;
importjava.util.Date;
importjava.util.Scanner;
publicclassMyCalendar
{
publicstaticvoidmain(String[]args)
{
Scannerscanner=newScanner(System.in);
Stringreg="^(\d+)[^\d]+((0?[1-9])|(1[012]))$";
while(true)
{
System.out.println("输入年月(年和月用非数字隔开:如2015.1)(什么都不输入直接退出)");
Stringline=scanner.nextLine().trim();
if("".equals(line))
{
scanner.close();
break;
}
if(!line.matches(reg))
{
continue;
}
intyear=Integer.parseInt(line.replaceAll(reg,"$1"));
intmonth=Integer.parseInt(line.replaceAll(reg,"$2"));
System.out.println("日 一 二 三 四 五 六");
Calendarcalendar=Calendar.getInstance();
//这个月的1号是星期几
calendar.set(year,month-1,1);
intday=calendar.get(Calendar.DAY_OF_WEEK);
intstart=Calendar.SUNDAY;
calendar.add(Calendar.DATE,-day+start);
while(start<day)
{
System.out.print(calendar.get(Calendar.DATE)+" ");
calendar.add(Calendar.DATE,1);
start++;
}
calendar.set(year,month-1,1);
Datenow=calendar.getTime();
calendar.set(year,month,1);
Datenext=calendar.getTime();
for(Datecur=now;cur.before(next);)
{
calendar.setTime(cur);
intx=calendar.get(Calendar.DATE);
Stringtmp=x<10?"0"+x:x+"";
System.out.print(tmp+" ");
if(calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY)
{
System.out.println();
}
calendar.add(Calendar.DATE,1);
cur=calendar.getTime();
}
calendar.add(Calendar.DATE,-1);
intto=calendar.get(Calendar.DAY_OF_WEEK);
intend=Calendar.SATURDAY;
while(to<end)
{
calendar.add(Calendar.DATE,1);
intx=calendar.get(Calendar.DATE);
Stringtmp=x<10?"0"+x:x+"";
System.out.print(tmp+" ");
to++;
}
System.out.println();
}
}
}
‘陆’ JAVA编写一个多功能万年历程序
import java.text.SimpleDateFormat; import java.util.Calendar; public class TestDate { public static final String[] weeks = { "日", "一", "二", "三", "四", "五", "六" }; public static void main(String[] args) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR,2011);//2011年 c.set(Calendar.MONTH,0);//java中Calendar类,月从0开始, 0代表一月 c.set(Calendar.DATE,1);//1号 int day = c.get(Calendar.DAY_OF_WEEK);//获致是本周的第几天地, 1代表星期天...7代表星期六 System.out.println(new SimpleDateFormat( "yyyy-MM-dd ").format(c.getTime())); System.out.println("星期" + weeks[day-1]); } } 把以上测试代码写作一个方法 方法的参数名为年月日, 即可。当然Calendar 还有很多功能,比如一周的第几天,一年的第几个月……
‘柒’ 用java语言编写万年历
给你一个现成的,我自己写的。
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
public class WanNianLi extends JFrame implements ActionListener {
private static int year,month,days;
private JButton[] btn=new JButton[days];
WanNianLi() {
super("万年历");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout bl=new GridLayout(5,7);
JPanel pane=new JPanel();
pane.setLayout(bl);
for (int i=0;i<days;i++) {
int temp=i+1;
btn[i]=new JButton(""+temp);
btn[i].addActionListener(this);
pane.add(btn[i]);
}
setContentPane(pane);
pack();
setLookAndFeel();
setVisible(true);
}
public static void main(String[] args) {
if (args.length>0)
year=Integer.parseInt(args[0]);
else
year=1982;
if (args.length>1)
month=Integer.parseInt(args[1]);
else
month=1;
GetDays gd=new GetDays(year,month);
days=gd.getDays();
new WanNianLi();
}
public void actionPerformed(ActionEvent evt) {
Object src=evt.getSource();
for (int i=0;i<days;i++)
if (src==btn[i]) {
int day=i+1;
GetWeekday gw=new GetWeekday(year,month,day);
String str="";
switch (gw.getWeekday()) {
case 1:
str="天";
break;
case 2:
str="一";
break;
case 3:
str="二";
break;
case 4:
str="三";
break;
case 5:
str="四";
break;
case 6:
str="五";
break;
case 7:
str="六";
break;
}
setTitle(year+"年"+month+"月"+day+"日"+"星期"+str);
repaint();
}
}
private void setLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception e){
System.out.print(e.toString());
}
}
}
//////////////
//获取星期几//
//////////////
class GetWeekday {
private Calendar cal=Calendar.getInstance();
private static int weekday;
public int getWeekday() {
return weekday;
}
GetWeekday(int y,int m,int d) {
cal.clear();
cal.set(Calendar.YEAR,y);
cal.set(Calendar.MONTH,m-1);
cal.set(Calendar.DAY_OF_MONTH,d);
weekday=cal.get(Calendar.DAY_OF_WEEK);
}
}
////////////////////
//获取当前月的天数//
////////////////////
class GetDays {
private static int days;
public int getDays() {
return days;
}
GetDays(int y,int m) {
GregorianCalendar gc=new GregorianCalendar();
switch (m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 4:
case 6:
case 9:
case 11:
days=30;
break;
case 2:
if (gc.isLeapYear(y))
days=29;
else
days=28;
break;
}
}
}