gpt4 book ai didi

java.time.Year.plusYears()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 21:40:40 27 4
gpt4 key购买 nike

本文整理了Java中java.time.Year.plusYears()方法的一些代码示例,展示了Year.plusYears()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Year.plusYears()方法的具体详情如下:
包路径:java.time.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: com.github.seratch/java-time-backport

/**
 * 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: org.codehaus.groovy/groovy-datetime

/**
 * Returns a {@link java.time.Year} that is {@code years} years after this year.
 *
 * @param self  a Year
 * @param years the number of years to add
 * @return a Year
 * @since 2.5.0
 */
public static Year plus(final Year self, long years) {
  return self.plusYears(years);
}

代码示例来源:origin: com.sqlapp/sqlapp-core

/**
 * 年の加算を実行します
 * 
 * @param date
 *            日付型
 * @param years
 *            加算する年
 * @return 年を加算した結果のカレンダー
 */
public static Year addYears(final Year date, final int years) {
  if (date == null) {
    return null;
  }
  return date.plusYears(years);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * {@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.xbib/catalog-entities

private String convertFromMarcDate(String date) {
    if (date.indexOf('|') >= 0) {
      // invalid date / no date
      return null;
    }
    try {
      // yy maps to 2000-2099 which is wrong, cataloging era is somewhere around 1970-2070
      LocalDate localDatetime = LocalDate.parse(date, formatter);
      // adjust year. If in the future, subtract 100 to go back to 20th century cataloging.
      // one year tolerance, maybe "future cataloging"
      if (localDatetime.getYear() > Year.now().plusYears(1).getValue()) {
        localDatetime = localDatetime.minusYears(100);
      }
      return localDatetime.toString();
    } catch (Exception e) {
      logger.log(Level.WARNING, "unable to convert date: " + date, e);
      return date;
    }
  }
}

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