例:今天 是2007-3-16号。
可以得到今天所在的周是本年的第11周,同时要把本月16号前,和16号的几周算出来。(注:一个月可能有4周,5周,6周三种)
已解决,用了个笨点方法,不知道有无更好的:代码如下,你打印下就知道我说的什么意思了:
[CODE]
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
public class A {
public static void main(String[] args) throws IOException {
List weekOfYearList = new ArrayList();
Calendar c =new GregorianCalendar();
c.setTime(new Date());
c.set(Calendar.DATE,1);
c.setFirstDayOfWeek(Calendar.MONDAY);
int returnWeekFirst=c.get(Calendar.WEEK_OF_YEAR); //get first week of year;
weekOfYearList.add(new Integer(returnWeekFirst));
int dayOfWeek=c.get(Calendar.DAY_OF_WEEK)-1; //get first day of week
int maxDayOfMonth=c.getActualMaximum(Calendar.DAY_OF_MONTH);
int nextDayOfWeek=7-dayOfWeek;
//get other week of year
for(int i=nextDayOfWeek;i<maxDayOfMonth;i=i+7){
nextDayOfWeek=nextDayOfWeek+7;
c.set(Calendar.DATE,nextDayOfWeek);
c.setFirstDayOfWeek(Calendar.MONDAY);
int returnWeekNextDayOfWeek=c.get(Calendar.WEEK_OF_YEAR);
weekOfYearList.add(new Integer(returnWeekNextDayOfWeek));
}
/** ************print***************** **/
for(int j=0;j<weekOfYearList.size();j++){
System.out.println(weekOfYearList.get(j));
}
}
}
[/CODE]