我正在使用以下代码显示一周中的所有日期,但是每当我选择一周的最后一个日期时,它就会打印下周的日期。为什么会发生这种情况?我的代码有什么问题吗?
/**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);
}
输出显示日期从
22-april-2013 to 28-april-2013
但应该是
15-april-2013 to 21-april-2013