I am using GregorianCalendar as it follows
new GregorianCalendar(1900, Calendar.JANUARY, 1)
and returns a date starting from Tuesday.
Is there any way to configure it in order to return as first day of the week the 'Sunday'.
I want to return a Calendar object.
I used the following solution
switch (gregorianCalendar.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
gregorianCalendar.add(Calendar.DAY_OF_WEEK, -1);
break;
case Calendar.TUESDAY:
gregorianCalendar.add(Calendar.DAY_OF_WEEK, -2);
break;
case Calendar.WEDNESDAY:
gregorianCalendar.add(Calendar.DAY_OF_WEEK, -3);
break;
case Calendar.THURSDAY:
gregorianCalendar.add(Calendar.DAY_OF_WEEK, -4);
break;
case Calendar.FRIDAY:
gregorianCalendar.add(Calendar.DAY_OF_WEEK, -5);
break;
case Calendar.SATURDAY:
gregorianCalendar.add(Calendar.DAY_OF_WEEK, -6);
break;
}
I don't know if its the best one.
I understand you are looking for previous Sunday ? Then I would rather do something like:
while (gregorianCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { gregorianCalendar.add(Calendar.DAY_OF_WEEK, -1); }