gpt4 book ai didi

android - 如何使用 caldroid 库设置月份的开始和结束日期(日期)?

转载 作者:行者123 更新时间:2023-11-29 17:13:11 26 4
gpt4 key购买 nike

如果我想从 2016 年 1 月 15 日到 2016 年 2 月 16 日开始的月份修改日历,如何在 calroid 日历库中更改月份的开始日期和结束日期。

最佳答案

您好,您可以在 CalendarHelper 类中使用以下修改,您可以为轮类日历设置月份的开始日期。我正在使用以下库查看日历 https://github.com/roomorama/Caldroid

请修改getFullWeeks方法

/** * 检索给定日历月的所有日期包括上个月, * 当前月份和下个月。 * * @param 月份 * @param 年 * @param startDayOfWeek : 日历可以从自定义日期而不是星期日开始 * @返回 */

   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;
}

希望这对你有帮助:)

关于android - 如何使用 caldroid 库设置月份的开始和结束日期(日期)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39996235/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com