java.time.Period.plusMonths()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(131)

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

Period.plusMonths介绍

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

This adds the amount to the months unit in a copy of this period. The years and days units are unaffected. For example, "1 year, 6 months and 3 days" plus 2 months returns "1 year, 8 months and 3 days".

This instance is immutable and unaffected by this method call.
[中]返回添加了指定月份的此期间的副本。
这会将金额添加到此期间副本中的月份单位。年和日单位不受影响。例如,“1年6个月3天”加上2个月返回“1年8个月3天”。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testLifecycle() {
  doInJPA( this::entityManagerFactory, entityManager -> {
    Event event = new Event( period );
    entityManager.persist( event );
  } );
  doInJPA( this::entityManagerFactory, entityManager -> {
    Event event = entityManager.createQuery( "from Event", Event.class ).getSingleResult();
    assertEquals( period, event.getSpan() );
  } );
  doInJPA( this::entityManagerFactory, entityManager -> {
    //tag::basic-jpa-convert-period-string-converter-immutability-plan-example[]
    Event event = entityManager.createQuery( "from Event", Event.class ).getSingleResult();
    event.setSpan(Period
      .ofYears( 3 )
      .plusMonths( 2 )
      .plusDays( 1 )
    );
    //end::basic-jpa-convert-period-string-converter-immutability-plan-example[]
  } );
}

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

/**
 * Returns a copy of this period with the specified months subtracted.
 * <p>
 * This subtracts the amount from the months unit in a copy of this period.
 * The years and days units are unaffected.
 * For example, "1 year, 6 months and 3 days" minus 2 months returns "1 year, 4 months and 3 days".
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param monthsToSubtract  the years to subtract, positive or negative
 * @return a {@code Period} based on this period with the specified months subtracted, not null
 * @throws ArithmeticException if numeric overflow occurs
 */
public Period minusMonths(long monthsToSubtract) {
  return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
}

代码示例来源:origin: OpenGamma/Strata

public static String[] fwdIdValue(
  int tenor,
  double fwdFixingQuote,
  double[] fwdFraQuotes,
  double[] fwdIrsQuotes,
  Period[] fwdFraTenors,
  Period[] fwdIrsTenors) {
 String[] fwdIdValue = new String[1 + fwdFraQuotes.length + fwdIrsQuotes.length];
 fwdIdValue[0] = "FIXING" + tenor + "M";
 for (int i = 0; i < fwdFraQuotes.length; i++) {
  fwdIdValue[i + 1] = "FRA" + fwdFraTenors[i].toString() + "x" + fwdFraTenors[i].plusMonths(tenor).toString();
 }
 for (int i = 0; i < fwdIrsQuotes.length; i++) {
  fwdIdValue[i + 1 + fwdFraQuotes.length] = "IRS" + tenor + "M-" + fwdIrsTenors[i].toString();
 }
 return fwdIdValue;
}

代码示例来源:origin: net.time4j/time4j-core

break;
case QUARTERS:
  period = period.plusMonths(Math.multiplyExact(amount, 3));
  break;
case MONTHS:
  period = period.plusMonths(amount);
  break;
case WEEKS:

相关文章