Here you can find the source of getStartAndEndDatesForWeek(Calendar currentDate, Calendar startDate, Calendar endDate)
public static void getStartAndEndDatesForWeek(Calendar currentDate, Calendar startDate, Calendar endDate)
//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)); } }