I just wanna ask what is the efficient way to get the week numbers of a certain month. I have a function with month number & year as arguments, the return value of the function should be a int array which contain the week numbers of the specific month.(like following…)
public int[] getWeeksOfMonth(int month, int year){
//what's the efficient way to implement this??
}
The
WEEK_OF_YEARattribute of theCalendarclass can be usefull for you.Create a new date that will be the first day of the given month. Get the week of the year for this day, let say you got
startvalue.Create a new date that will be the last day of the given month. Get the week of the year for this day, so now you got
endvalue.Finally, create a simple
int[]that will contains values fromstarttoend.