gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-18 00:22:40 32 4
gpt4 key购买 nike

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

YearMonth.plusYears介绍

[英]Returns a copy of this year-month with the specified period in 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-month with the specified period in 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 YearMonth} based on this year-month with the years subtracted, not null
 * @throws DateTimeException if the result exceeds the supported range
 */
public YearMonth minusYears(long yearsToSubtract) {
  return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
}

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

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

代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker

/**
 * buttonNextYearActionPerformed, This event is called when the next year button is pressed.
 * This sets the YearMonth of the calendar to the next year, and redraws the calendar.
 */
private void buttonNextYearActionPerformed(ActionEvent e) {
  // We catch and ignore any exceptions at the minimum and maximum of the local date range.
  try {
    drawCalendar(displayedYearMonth.plusYears(1));
  } catch (Exception ex) {
  }
}

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

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public YearMonth plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case MONTHS: return plusMonths(amountToAdd);
      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: com.github.lgooddatepicker/LGoodDatePicker

YearMonth choiceYearMonth = displayedYearMonth.plusYears(yearDifference);
String choiceYearMonthString = "" + choiceYearMonth.getYear();
yearPopupMenu.add(new JMenuItem(new AbstractAction(choiceYearMonthString) {

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

/**
 * 年の加算を実行します
 * 
 * @param date
 *            日付型
 * @param years
 *            加算する年
 * @return 年を加算した結果のカレンダー
 */
@SuppressWarnings("unchecked")
public static <T extends Temporal> T addYears(final T date, final int years) {
  if (date == null) {
    return null;
  }
  if (date instanceof LocalDate){
    return (T)((LocalDate)date).plusYears(years);
  }else if (date instanceof LocalDateTime){
    return (T)((LocalDateTime)date).plusYears(years);
  }else if (date instanceof OffsetDateTime){
    return (T)((OffsetDateTime)date).plusYears(years);
  }else if (date instanceof ZonedDateTime){
    return (T)((ZonedDateTime)date).plusYears(years);
  }else if (date instanceof YearMonth){
    return (T)((YearMonth)date).plusYears(years);
  }
  return (T)date.plus(Duration.of(years, ChronoUnit.YEARS));
}

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