trzeba użyć klasy java.util.Calendar
. Możesz ustawić rok za pomocą Calendar.YEAR
i tygodnia w roku przy pomocy Calendar.WEEK_OF_YEAR
, używając metody public void set(int field, int value)
.
Dopóki ustawienia regionalne są ustawione prawidłowo, można nawet użyć setFirstDayOfWeek
, aby zmienić pierwszy dzień tygodnia. Data reprezentowana przez instancję kalendarza będzie datą początkową. Po prostu dodaj 6 dni na datę zakończenia.
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();
Próbowałem używać MonthDisplayHelper & JodaTime, ale jakoś nie udało się osiągnąć wymaganego. Thanx Sunil & Chase .. spróbuje rozwiązać problem i poznajemy – AndroidGuy