public static Date getDateofMonth(int year,int month){
Calendar cal=Calendar.getInstance();
cal.set(cal.MONTH,month-1);
cal.set(cal.YEAR,year);
cal.set(cal.DAY_OF_MONTH,1);
int dayofweek=cal.get(cal.DAY_OF_WEEK);
if(dayofweek>4){
cal.set(cal.WEEK_OF_MONTH,4);
}else{
cal.set(cal.WEEK_OF_MONTH,3);
}
cal.set(cal.DAY_OF_WEEK,4);
return cal.getTime();
}
Calendar cal=Calendar.getInstance();
cal.set(cal.MONTH,month-1);
cal.set(cal.YEAR,year);
cal.set(cal.DAY_OF_MONTH,1);
int dayofweek=cal.get(cal.DAY_OF_WEEK);
if(dayofweek>4){
cal.set(cal.WEEK_OF_MONTH,4);
}else{
cal.set(cal.WEEK_OF_MONTH,3);
}
cal.set(cal.DAY_OF_WEEK,4);
return cal.getTime();
}
調用getDateofMonth(2007,2);
就行了,哈哈,謝謝大家的幫助
**************************************************************
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.MONTH,某月的月份);//注意這個月份是從0開始的
cal.set(Calendar.WEEK_OF_MONTH,3);
cal.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
cal.getTime();//這個應該就是你要的日期了
cal.setTime(new Date());
cal.set(Calendar.MONTH,某月的月份);//注意這個月份是從0開始的
cal.set(Calendar.WEEK_OF_MONTH,3);
cal.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
cal.getTime();//這個應該就是你要的日期了
?
******************************************************
?
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.set(Calendar.YEAR,2007);//2007 current year
c.set(Calendar.MONTH,(4-1));//4 current month
c.set(Calendar.DATE,1);
c.set(Calendar.WEEK_OF_MONTH,
c.get(Calendar.DAY_OF_WEEK)>Calendar.WEDNESDAY?4:3);
c.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
c.getTime();
c.setTime(new Date());
c.set(Calendar.YEAR,2007);//2007 current year
c.set(Calendar.MONTH,(4-1));//4 current month
c.set(Calendar.DATE,1);
c.set(Calendar.WEEK_OF_MONTH,
c.get(Calendar.DAY_OF_WEEK)>Calendar.WEDNESDAY?4:3);
c.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
c.getTime();
System.out.println(c.getTime());
?


文章來源:http://21958978.spaces.live.com/Blog/cns!A7DF246804AD47BB!204.entry