心的方向

新的征途......
posts - 75,comments - 19,trackbacks - 0
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();
}

调用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();//这个应该就是你要的日期了
 
******************************************************
 
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();
System.out.println(c.getTime());
 

文章来源:http://21958978.spaces.live.com/Blog/cns!A7DF246804AD47BB!204.entry
posted on 2007-03-31 10:49 阿伟 阅读(282) 评论(0)  编辑  收藏 所属分类: J2EE

只有注册用户登录后才能发表评论。


网站导航: