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

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

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

LocalDate.plusMonths介绍

[英]Returns a copy of this LocalDate with the specified period in months added.

This method adds the specified amount to the months field in three steps:

  1. Add the input months to the month-of-year field
  2. Check if the resulting date would be invalid
  3. Adjust the day-of-month to the last valid day if necessary

For example, 2007-03-31 plus one month would result in the invalid date 2007-04-31. Instead of returning an invalid result, the last valid day of the month, 2007-04-30, is selected instead.

This instance is immutable and unaffected by this method call.
[中]返回此LocalDate的副本,并添加指定的期间(以月为单位)。
此方法分三步将指定金额添加到“月份”字段:
1.将输入月份添加到“年度月份”字段
1.检查结果日期是否无效
1.如有必要,将月份日期调整为最后一个有效日期
例如,2007-03-31加上一个月将导致无效日期2007-04-31。将选择月份的最后一个有效日期2007-04-30,而不是返回无效结果。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

@Override public CalendarDay getItem(final int position) {
  return CalendarDay.from(min.getDate().plusMonths(position));
 }
}

代码示例来源:origin: shrikanth7698/Collapsible-Calendar-View-Android

public void nextMonth() {
  mCal = mCal.plusMonths(1);
}

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

/**
 * Returns a copy of this {@code LocalDate} with the specified period in months subtracted.
 * <p>
 * This method subtracts the specified amount from the months field in three steps:
 * <ol>
 * <li>Subtract the input months to the month-of-year field</li>
 * <li>Check if the resulting date would be invalid</li>
 * <li>Adjust the day-of-month to the last valid day if necessary</li>
 * </ol>
 * <p>
 * For example, 2007-03-31 minus one month would result in the invalid date
 * 2007-02-31. Instead of returning an invalid result, the last valid day
 * of the month, 2007-02-28, is selected instead.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param monthsToSubtract  the months to subtract, may be negative
 * @return a {@code LocalDate} based on this date with the months subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDate minusMonths(long monthsToSubtract) {
  return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
}

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

/**
 * Returns a copy of this {@code LocalDate} with the specified period in months subtracted.
 * <p>
 * This method subtracts the specified amount from the months field in three steps:
 * <ol>
 * <li>Subtract the input months to the month-of-year field</li>
 * <li>Check if the resulting date would be invalid</li>
 * <li>Adjust the day-of-month to the last valid day if necessary</li>
 * </ol>
 * <p>
 * For example, 2007-03-31 minus one month would result in the invalid date
 * 2007-02-31. Instead of returning an invalid result, the last valid day
 * of the month, 2007-02-28, is selected instead.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param monthsToSubtract  the months to subtract, may be negative
 * @return a {@code LocalDate} based on this date with the months subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDate minusMonths(long monthsToSubtract) {
  return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
}

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

@Override
ThaiBuddhistDate plusMonths(long months) {
  return with(isoDate.plusMonths(months));
}

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

@Override
MinguoDate plusMonths(long months) {
  return with(isoDate.plusMonths(months));
}

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

@Override
MinguoDate plusMonths(long months) {
  return with(isoDate.plusMonths(months));
}

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

@Override
JapaneseDate plusMonths(long months) {
  return with(isoDate.plusMonths(months));
}

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

@Override
JapaneseDate plusMonths(long months) {
  return with(isoDate.plusMonths(months));
}

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

@Override
ThaiBuddhistDate plusMonths(long months) {
  return with(isoDate.plusMonths(months));
}

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

/**
 * Returns a copy of this {@code LocalDateTime} with the specified period in months added.
 * <p>
 * This method adds the specified amount to the months field in three steps:
 * <ol>
 * <li>Add the input months to the month-of-year field</li>
 * <li>Check if the resulting date would be invalid</li>
 * <li>Adjust the day-of-month to the last valid day if necessary</li>
 * </ol>
 * <p>
 * For example, 2007-03-31 plus one month would result in the invalid date
 * 2007-04-31. Instead of returning an invalid result, the last valid day
 * of the month, 2007-04-30, is selected instead.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param months  the months to add, may be negative
 * @return a {@code LocalDateTime} based on this date-time with the months added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDateTime plusMonths(long months) {
  LocalDate newDate = date.plusMonths(months);
  return with(newDate, time);
}

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

/**
 * Returns a copy of this {@code LocalDateTime} with the specified period in months added.
 * <p>
 * This method adds the specified amount to the months field in three steps:
 * <ol>
 * <li>Add the input months to the month-of-year field</li>
 * <li>Check if the resulting date would be invalid</li>
 * <li>Adjust the day-of-month to the last valid day if necessary</li>
 * </ol>
 * <p>
 * For example, 2007-03-31 plus one month would result in the invalid date
 * 2007-04-31. Instead of returning an invalid result, the last valid day
 * of the month, 2007-04-30, is selected instead.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param months  the months to add, may be negative
 * @return a {@code LocalDateTime} based on this date-time with the months added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDateTime plusMonths(long months) {
  LocalDate newDate = date.plusMonths(months);
  return with(newDate, time);
}

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

long qoy = qoyLong;
  date = LocalDate.of(y, 1, 1);
  date = date.plusMonths(Jdk8Methods.safeMultiply(Jdk8Methods.safeSubtract(qoy, 1), 3));
  date = date.plusDays(Jdk8Methods.safeSubtract(doq, 1));
} else {

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

long qoy = qoyLong;
  date = LocalDate.of(y, 1, 1);
  date = date.plusMonths(Jdk8Methods.safeMultiply(Jdk8Methods.safeSubtract(qoy, 1), 3));
  date = date.plusDays(Jdk8Methods.safeSubtract(doq, 1));
} else {

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

long months = Jdk8Methods.safeSubtract(moy, 1);
  long days = Jdk8Methods.safeSubtract(dom, 1);
  return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
} else if (resolverStyle == ResolverStyle.SMART){
  DAY_OF_MONTH.checkValidValue(dom);
    long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
    long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
    return LocalDate.of(y, 1, 1).plusMonths(months).plusWeeks(weeks).plusDays(days);
    long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
    long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
    return LocalDate.of(y, 1, 1).plusMonths(months).plusWeeks(weeks).plusDays(days);

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

if (totalMonths > 0 && days < 0) {
  totalMonths--;
  LocalDate calcDate = this.plusMonths(totalMonths);
  days = (int) (end.toEpochDay() - calcDate.toEpochDay());  // safe
} else if (totalMonths < 0 && days > 0) {

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

if (totalMonths > 0 && days < 0) {
  totalMonths--;
  LocalDate calcDate = this.plusMonths(totalMonths);
  days = (int) (end.toEpochDay() - calcDate.toEpochDay());  // safe
} else if (totalMonths < 0 && days > 0) {

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

case DAYS: return plusDays(amountToAdd);
case WEEKS: return plusWeeks(amountToAdd);
case MONTHS: return plusMonths(amountToAdd);
case YEARS: return plusYears(amountToAdd);
case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));

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

case DAYS: return plusDays(amountToAdd);
case WEEKS: return plusWeeks(amountToAdd);
case MONTHS: return plusMonths(amountToAdd);
case YEARS: return plusYears(amountToAdd);
case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));

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

case ALIGNED_WEEK_OF_YEAR: return plusWeeks(newValue - getLong(ALIGNED_WEEK_OF_YEAR));
case MONTH_OF_YEAR: return withMonth((int) newValue);
case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
case YEAR_OF_ERA: return withYear((int) (year >= 1 ? newValue : 1 - newValue));
case YEAR: return withYear((int) newValue);

相关文章