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

x33g5p2x  于2022-02-05 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(102)

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

Year.plusYears介绍

[英]Returns a copy of this year with the specified number of years added.

This instance is immutable and unaffected by this method call.
[中]返回添加了指定年份数的本年副本。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

/**
 * Returns a copy of this year with the specified number of years subtracted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param yearsToSubtract  the years to subtract, may be negative
 * @return a {@code Year} based on this year with the period subtracted, not null
 * @throws DateTimeException if the result exceeds the supported year range
 */
public Year minusYears(long yearsToSubtract) {
  return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
}

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

/**
 * Returns a copy of this year with the specified number of years subtracted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param yearsToSubtract  the years to subtract, may be negative
 * @return a {@code Year} based on this year with the period subtracted, not null
 * @throws DateTimeException if the result exceeds the supported year range
 */
public Year minusYears(long yearsToSubtract) {
  return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
}

代码示例来源:origin: stackoverflow.com

Year thisYear = Year.from( today );
Year nextYear = thisYear.plusYears( 1 );
Year lastYear = thisYear.minusYears( 1 );

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

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Year plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case YEARS: return plusYears(amountToAdd);
      case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
      case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
      case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
      case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
    }
    throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
  }
  return unit.addTo(this, amountToAdd);
}

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

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Year plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case YEARS: return plusYears(amountToAdd);
      case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
      case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
      case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
      case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
    }
    throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
  }
  return unit.addTo(this, amountToAdd);
}

相关文章

微信公众号

最新文章

更多