I am using the following code to display all the day of a week, but whenever I select the last date of a week then it prints the date of next week. Why this happens? Is anything wrong with my code?
/**Calendar week start on Monday**/
Calendar selectedDate = Calendar.getInstance(Locale.US);
// Set current date to 21-april-2013
selectedDate.set(selectedDate.get(Calendar.YEAR), selectedDate.get(Calendar.MONTH), 21);
// create another instance of calendar
Calendar c = Calendar.getInstance(Locale.US);
// set current date to this new calendar instance
c = (Calendar) selectedDate.clone();
// Set the calendar to monday of the current week
c.setFirstDayOfWeek(Calendar.MONDAY);
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// Print dates of the current week starting on Monday
DateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
for (int i = 0; i < 7; i++)
{
System.out.println(df.format(c.getTime()));
c.add(Calendar.DATE, 1);
}
OutPut shows date from
22-april-2013 to 28-april-2013
But it should be
15-april-2013 to 21-april-2013