You need to use the java.util.Calendar
class. You can set the year using Calendar.YEAR
and the week of the year using Calendar.WEEK_OF_YEAR
using the public void set(int field, int value)
method.
If the language is set correctly, you can use setFirstDayOfWeek
to change the first day of the week. The date indicated by your calendar instance will be your start date. Just add 6 days for your end date.
Calendar calendar = new GregorianCalendar(); // Clear the calendar since the default is the current time calendar.clear(); // Directly set year and week of year calendar.set(Calendar.YEAR, 2011); calendar.set(Calendar.WEEK_OF_YEAR, 51); // Start date for the week Date startDate = calendar.getTime(); // Add 6 days to reach the last day of the current week calendar.add(Calendar.DAY_OF_YEAR, 6); // End date for the week Date endDate = calendar.getTime();
Chase
source share