Android Week Get getStartAndEndDatesForWeek(Calendar currentDate, Calendar startDate, Calendar endDate)

Here you can find the source of getStartAndEndDatesForWeek(Calendar currentDate, Calendar startDate, Calendar endDate)

Description

get Start And End Dates For Week

Declaration

public static void getStartAndEndDatesForWeek(Calendar currentDate,
            Calendar startDate, Calendar endDate) 

Method Source Code

//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void getStartAndEndDatesForWeek(Calendar currentDate,
            Calendar startDate, Calendar endDate) {
        Calendar cal = (Calendar) currentDate.clone();
        int i = 0;
        while (i < 8 && Calendar.SUNDAY != cal.get(Calendar.DAY_OF_WEEK)) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
            i++;/*from   www .ja  v  a 2s.  c  o  m*/
        }
        if (i == 0) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        // Remove below line if week is needed to be started on Monday
        cal.add(Calendar.DAY_OF_MONTH, 1);
        startDate
                .set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
        startDate.set(Calendar.MONTH, cal.get(Calendar.MONTH));
        startDate.set(Calendar.YEAR, cal.get(Calendar.YEAR));

        cal.add(Calendar.DAY_OF_MONTH, 6);

        endDate.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
        endDate.set(Calendar.MONTH, cal.get(Calendar.MONTH));
        endDate.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    }
}

Related

  1. getDateAWeekAgo(Date date)
  2. getDateInAWeek(Date date)
  3. getWeeksSinceEpochFromJulianDay(int julianDay, int firstDayOfWeek)
  4. getDaysOfWeekNames()
  5. getDaysOfWeekNames(Locale l, int len)
  6. getEnglishDayInWeek(Date date)
  7. getFirstDayOfFirstWeekOfMonth(final Calendar cal)