如果我想修改2016年1月15日至2016年2月16日期间的月历,我将如何更改calroid calendar lib中月份的开始日期和结束日期。
答案 0 :(得分:3)
请修改getFullWeeks方法
/ ** *检索给定日历月的所有日期包括上个月, *当月和下个月。 * * @param月 * @param年 * @param startDayOfWeek:日历可以从自定义日期而不是星期日开始 * @return * /
public static ArrayList<DateTime> getFullWeeks(int month, int year, int startDayOfWeek,int startDayOfMonth, boolean sixWeeksInCalendar) {
ArrayList<DateTime> datetimeList = new ArrayList<DateTime>();
int dayCount=startDayOfMonth;
DateTime firstDateOfMonth = new DateTime(year, month, 1, 0, 0, 0, 0);
DateTime firstDateOfMonthToSet = new DateTime(year, month, dayCount, 0, 0, 0, 0);
int daysToAdd=firstDateOfMonth.getNumDaysInMonth()-dayCount;
DateTime lastDateOfMonth = firstDateOfMonthToSet.plusDays(daysToAdd);
DateTime lastDateOfMonthTpSet =firstDateOfMonthToSet.plusDays(firstDateOfMonth.getNumDaysInMonth()-1);
// Add dates of first week from previous month
// int weekdayOfFirstDate = firstDateOfMonth.getWeekDay();
//dr
int weekdayOfFirstDate = firstDateOfMonthToSet.getWeekDay();
// If weekdayOfFirstDate smaller than startDayOfWeek
// For e.g: weekdayFirstDate is Monday, startDayOfWeek is Tuesday
// increase the weekday of FirstDate because it's in the future
if (weekdayOfFirstDate < startDayOfWeek) {
weekdayOfFirstDate += 7;
}
while (weekdayOfFirstDate > 0) {
DateTime dateTime = firstDateOfMonthToSet.minusDays(weekdayOfFirstDate
- startDayOfWeek);
if (!dateTime.lt(firstDateOfMonthToSet)) {
break;
}
datetimeList.add(dateTime);
weekdayOfFirstDate--;
}
// Add dates of current month
for (int i = 0; i < lastDateOfMonth.getDay(); i++) {
datetimeList.add(firstDateOfMonthToSet.plusDays(i));
}
// Add dates of last week from next month
int endDayOfWeek = startDayOfWeek - 1;//dr
// int endDayOfWeek = startDayOfWeek;
if (endDayOfWeek == 0) {
endDayOfWeek = 7;
}
if (lastDateOfMonthTpSet.getWeekDay() != endDayOfWeek) {
int i = 1;
while (true) {
DateTime nextDay = lastDateOfMonthTpSet.plusDays(i);
datetimeList.add(nextDay);
i++;
if (nextDay.getWeekDay() == endDayOfWeek) {
break;
}
}
}
// Add more weeks to fill remaining rows
if (sixWeeksInCalendar) {
int size = datetimeList.size();
int row = size / 7;
int numOfDays = (6 - row) * 7;
DateTime lastDateTime = datetimeList.get(size - 1);
for (int i = 1; i <= numOfDays; i++) {
DateTime nextDateTime = lastDateTime.plusDays(i);
datetimeList.add(nextDateTime);
}
}
return datetimeList;
}
希望这会对你有所帮助:)。