org.threeten.bp.LocalDate.plusDays()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(212)

本文整理了Java中org.threeten.bp.LocalDate.plusDays()方法的一些代码示例,展示了LocalDate.plusDays()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.plusDays()方法的具体详情如下:
包路径:org.threeten.bp.LocalDate
类名称:LocalDate
方法名:plusDays

LocalDate.plusDays介绍

[英]Returns a copy of this LocalDate with the specified number of days added.

This method adds the specified amount to the days field incrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.

For example, 2008-12-31 plus one day would result in 2009-01-01.

This instance is immutable and unaffected by this method call.
[中]返回此LocalDate的副本,并添加指定的天数。
此方法将指定的金额添加到“天”字段中,并根据需要增加“月”和“年”字段,以确保结果仍然有效。仅当超过最大/最小年份时,结果才无效。
例如,2008-12-31加上一天将导致2009-01-01。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: prolificinteractive/material-calendarview

@Override protected void buildDayViews(
  final Collection<DayView> dayViews,
  final LocalDate calendar) {
 LocalDate temp = calendar;
 for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
  addDayView(dayViews, temp);
  temp = temp.plusDays(1);
 }
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override protected void buildDayViews(
  final Collection<DayView> dayViews,
  final LocalDate calendar) {
 LocalDate temp = calendar;
 for (int r = 0; r < DEFAULT_MAX_WEEKS; r++) {
  for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
   addDayView(dayViews, temp);
   temp = temp.plusDays(1);
  }
 }
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override
protected List<CalendarDay> doInBackground(@NonNull Void... voids) {
 try {
  Thread.sleep(2000);
 } catch (InterruptedException e) {
  e.printStackTrace();
 }
 LocalDate temp = LocalDate.now().minusMonths(2);
 final ArrayList<CalendarDay> dates = new ArrayList<>();
 for (int i = 0; i < 30; i++) {
  final CalendarDay day = CalendarDay.from(temp);
  dates.add(day);
  temp = temp.plusDays(5);
 }
 return dates;
}

代码示例来源:origin: prolificinteractive/material-calendarview

private void buildWeekDays(LocalDate calendar) {
 LocalDate local = calendar;
 for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
  WeekDayView weekDayView = new WeekDayView(getContext(), local.getDayOfWeek());
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
   weekDayView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
  }
  weekDayViews.add(weekDayView);
  addView(weekDayView);
  local = local.plusDays(1);
 }
}

代码示例来源:origin: prolificinteractive/material-calendarview

/**
 * Clear the previous selection, select the range of days from first to last, and finally
 * invalidate. First day should be before last day, otherwise the selection won't happen.
 *
 * @param first The first day of the range.
 * @param last The last day in the range.
 * @see CalendarPagerAdapter#setDateSelected(CalendarDay, boolean)
 */
public void selectRange(final CalendarDay first, final CalendarDay last) {
 selectedDates.clear();
 // Copy to start from the first day and increment
 LocalDate temp = LocalDate.of(first.getYear(), first.getMonth(), first.getDay());
 // for comparison
 final LocalDate end = last.getDate();
 while( temp.isBefore(end) || temp.equals(end) ) {
  selectedDates.add(CalendarDay.from(temp));
  temp = temp.plusDays(1);
 }
 invalidateSelectedDates();
}

代码示例来源:origin: prolificinteractive/material-calendarview

protected LocalDate resetAndGetWorkingCalendar() {
 final TemporalField firstDayOfWeek = WeekFields.of(this.firstDayOfWeek, 1).dayOfWeek();
 final LocalDate temp = getFirstViewDay().getDate().with(firstDayOfWeek, 1);
 int dow = temp.getDayOfWeek().getValue();
 int delta = getFirstDayOfWeek().getValue() - dow;
 //If the delta is positive, we want to remove a week
 boolean removeRow = showOtherMonths(showOtherDates) ? delta >= 0 : delta > 0;
 if (removeRow) {
  delta -= DEFAULT_DAYS_IN_WEEK;
 }
 return temp.plusDays(delta);
}

代码示例来源:origin: prolificinteractive/material-calendarview

CalendarDay lastVisibleCalendarDay = CalendarDay.from(lastVisibleCalendar.plusDays(1));
if (currentlySelectedDate.equals(calendarDayToShow) ||
  (currentlySelectedDate.isAfter(calendarDayToShow) && currentlySelectedDate.isBefore(
CalendarDay lastVisibleCalendarDay = CalendarDay.from(lastVisibleCalendar.plusDays(6));
if (currentlySelectedDate != null &&
  (currentlySelectedDate.equals(calendarDayToShow) || currentlySelectedDate.equals(

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDate} with the specified number of days subtracted.
 * <p>
 * This method subtracts the specified amount from the days field decrementing the
 * month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2009-01-01 minus one day would result in 2008-12-31.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param daysToSubtract  the days to subtract, may be negative
 * @return a {@code LocalDate} based on this date with the days subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDate minusDays(long daysToSubtract) {
  return (daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract));
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDate} with the specified number of days subtracted.
 * <p>
 * This method subtracts the specified amount from the days field decrementing the
 * month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2009-01-01 minus one day would result in 2008-12-31.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param daysToSubtract  the days to subtract, may be negative
 * @return a {@code LocalDate} based on this date with the days subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDate minusDays(long daysToSubtract) {
  return (daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract));
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
ThaiBuddhistDate plusDays(long days) {
  return with(isoDate.plusDays(days));
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
MinguoDate plusDays(long days) {
  return with(isoDate.plusDays(days));
}

代码示例来源:origin: org.threeten/threetenbp

@Override
MinguoDate plusDays(long days) {
  return with(isoDate.plusDays(days));
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
JapaneseDate plusDays(long days) {
  return with(isoDate.plusDays(days));
}

代码示例来源:origin: org.threeten/threetenbp

@Override
ThaiBuddhistDate plusDays(long days) {
  return with(isoDate.plusDays(days));
}

代码示例来源:origin: org.threeten/threetenbp

@Override
JapaneseDate plusDays(long days) {
  return with(isoDate.plusDays(days));
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDate} with the specified period in weeks added.
 * <p>
 * This method adds the specified amount in weeks to the days field incrementing
 * the month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2008-12-31 plus one week would result in 2009-01-07.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param weeksToAdd  the weeks to add, may be negative
 * @return a {@code LocalDate} based on this date with the weeks added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDate plusWeeks(long weeksToAdd) {
  return plusDays(Jdk8Methods.safeMultiply(weeksToAdd, 7));
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the specified period in days added.
 * <p>
 * This method adds the specified amount to the days field incrementing the
 * month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2008-12-31 plus one day would result in 2009-01-01.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param days  the days to add, may be negative
 * @return a {@code LocalDateTime} based on this date-time with the days added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDateTime plusDays(long days) {
  LocalDate newDate = date.plusDays(days);
  return with(newDate, time);
}

代码示例来源:origin: ThreeTen/threetenbp

@SuppressWarnings("unchecked")
  @Override
  public <R extends Temporal> R adjustInto(R temporal, long newValue) {
    if (isSupportedBy(temporal) == false) {
      throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
    }
    int newWby = range().checkValidIntValue(newValue, WEEK_BASED_YEAR);  // strict check
    LocalDate date = LocalDate.from(temporal);
    int dow = date.get(DAY_OF_WEEK);
    int week = getWeek(date);
    if (week == 53 && getWeekRange(newWby) == 52) {
      week = 52;
    }
    LocalDate resolved = LocalDate.of(newWby, 1, 4);  // 4th is guaranteed to be in week one
    int days = (dow - resolved.get(DAY_OF_WEEK)) + ((week - 1) * 7);
    resolved = resolved.plusDays(days);
    return (R) temporal.with(resolved);
  }
};

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Converts this to a transition.
 *
 * @param standardOffset  the active standard offset, not null
 * @param savingsBeforeSecs  the active savings in seconds
 * @return the transition, not null
 */
ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) {
  // copy of code in ZoneOffsetTransitionRule to avoid infinite loop
  LocalDate date = toLocalDate();
  date = deduplicate(date);
  LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time));
  ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs));
  LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset));
  ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs));
  return new ZoneOffsetTransition(dt, wallOffset, offsetAfter);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Converts this to a transition.
 *
 * @param standardOffset  the active standard offset, not null
 * @param savingsBeforeSecs  the active savings in seconds
 * @return the transition, not null
 */
ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) {
  // copy of code in ZoneOffsetTransitionRule to avoid infinite loop
  LocalDate date = toLocalDate();
  date = deduplicate(date);
  LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time));
  ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs));
  LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset));
  ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs));
  return new ZoneOffsetTransition(dt, wallOffset, offsetAfter);
}

相关文章