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

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

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

YearMonth.minusMonths介绍

[英]Returns a copy of this year-month with the specified period in months subtracted.

This instance is immutable and unaffected by this method call.
[中]返回减去指定期间(以月为单位)后的本年月份的副本。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

  1. /**
  2. * Returns a {@link java.time.YearMonth} that is {@code months} months before this year/month.
  3. *
  4. * @param self a YearMonth
  5. * @param months the number of months to subtract
  6. * @return a Year
  7. * @since 2.5.0
  8. */
  9. public static YearMonth minus(final YearMonth self, long months) {
  10. return self.minusMonths(months);
  11. }

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

  1. YearMonth ym = YearMonth.now( ZoneId.of( "America/Montreal" ) );
  2. YearMonth ymAgo = ym.minusMonths( 6 );

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

  1. /**
  2. * buttonPreviousMonthActionPerformed, This event is called when the previous month button is
  3. * pressed. This sets the YearMonth of the calendar to the previous month, and redraws the
  4. * calendar.
  5. */
  6. private void buttonPreviousMonthActionPerformed(ActionEvent e) {
  7. // We catch and ignore any exceptions at the minimum and maximum of the local date range.
  8. try {
  9. drawCalendar(displayedYearMonth.minusMonths(1));
  10. } catch (Exception ex) {
  11. }
  12. }

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

  1. YearMonth date = new YearMonth("2014-01");
  2. date = date.minusMonths(1); //will equal 2013-11

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

  1. YearMonth thisMonth = YearMonth.now();
  2. YearMonth lastMonth = thisMonth.minusMonths(1);
  3. YearMonth twoMonthsAgo = thisMonth.minusMonths(2);
  4. DateTimeFormatter monthYearFormatter = DateTimeFormatter.ofPattern("MMMM yyyy");
  5. System.out.printf("Today: %s\n", thisMonth.format(monthYearFormatter));
  6. System.out.printf("Last Month: %s\n", lastMonth.format(monthYearFormatter));
  7. System.out.printf("Two Months Ago: %s\n", twoMonthsAgo.format(monthYearFormatter));

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueChangeTest() {
  3. return YearMonth.now().minusMonths(2).format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueCloneTest() {
  3. return YearMonth.now().minusMonths(1).format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

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

  1. ZonedId zoneId = ZoneId.of( "America/Montreal" );
  2. YearMonth yearMonthNow = YearMonth.now( zoneId );
  3. YearMonth yearMonthPrevious = yearMonthNow.minusMonths( 1 );
  4. LocalDate firstOfMonth = yearMonthPrevious.atDay( 1 );
  5. LocalDate lastOfMonth = yearMonthPrevious.atEndOfMonth();

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

  1. public void test_valuePointSensitivity_fixing() {
  2. SimplePriceIndexValues test = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
  3. PriceIndexObservation obs = PriceIndexObservation.of(US_CPI_U, VAL_MONTH.minusMonths(3));
  4. assertEquals(test.valuePointSensitivity(obs), PointSensitivityBuilder.none());
  5. }

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

  1. public void test_valuePointSensitivity_fixing() {
  2. HistoricPriceIndexValues test = HistoricPriceIndexValues.of(US_CPI_U, VAL_DATE, USCPI_TS);
  3. PriceIndexObservation obs = PriceIndexObservation.of(US_CPI_U, VAL_MONTH.minusMonths(3));
  4. assertEquals(test.value(obs), 234.722d, TOLERANCE_VALUE);
  5. assertEquals(test.valuePointSensitivity(obs), PointSensitivityBuilder.none());
  6. }

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

  1. public void test_createRateComputation_InterpolatedJapan() {
  2. LocalDate date1 = LocalDate.of(2013, 3, 9);
  3. LocalDate date2 = LocalDate.of(2013, 3, 10);
  4. LocalDate date3 = LocalDate.of(2013, 3, 11);
  5. InflationRateCalculation test = InflationRateCalculation.builder()
  6. .index(JP_CPI_EXF)
  7. .lag(Period.ofMonths(3))
  8. .indexCalculationMethod(INTERPOLATED_JAPAN)
  9. .firstIndexValue(START_INDEX)
  10. .build();
  11. double weight1 = 1.0 - (9.0 + 28.0 - 10.0) / 28.0;
  12. double weight2 = 1.0;
  13. double weight3 = 1.0 - 1.0 / 31.0;
  14. InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(
  15. JP_CPI_EXF, START_INDEX, YearMonth.from(date1).minusMonths(4), weight1);
  16. InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(
  17. JP_CPI_EXF, START_INDEX, YearMonth.from(date2).minusMonths(3), weight2);
  18. InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(
  19. JP_CPI_EXF, START_INDEX, YearMonth.from(date3).minusMonths(3), weight3);
  20. assertEquals(test.createRateComputation(date1), obs1);
  21. assertEquals(test.createRateComputation(date2), obs2);
  22. assertEquals(test.createRateComputation(date3), obs3);
  23. }

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

  1. public void test_createRateComputation_Monthly() {
  2. InflationRateCalculation test = InflationRateCalculation.builder()
  3. .index(GB_HICP)
  4. .lag(Period.ofMonths(3))
  5. .indexCalculationMethod(MONTHLY)
  6. .firstIndexValue(START_INDEX)
  7. .build();
  8. InflationEndMonthRateComputation obs1 = InflationEndMonthRateComputation.of(
  9. GB_HICP, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3));
  10. InflationEndMonthRateComputation obs2 = InflationEndMonthRateComputation.of(
  11. GB_HICP, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3));
  12. InflationEndMonthRateComputation obs3 = InflationEndMonthRateComputation.of(
  13. GB_HICP, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3));
  14. assertEquals(test.createRateComputation(DATE_2015_02_05), obs1);
  15. assertEquals(test.createRateComputation(DATE_2015_03_07), obs2);
  16. assertEquals(test.createRateComputation(DATE_2015_04_05), obs3);
  17. }

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

  1. public void test_createRateComputation_Interpolated() {
  2. InflationRateCalculation test = InflationRateCalculation.builder()
  3. .index(CH_CPI)
  4. .lag(Period.ofMonths(3))
  5. .indexCalculationMethod(INTERPOLATED)
  6. .firstIndexValue(START_INDEX)
  7. .build();
  8. double weight1 = 1.0 - 4.0 / 28.0;
  9. double weight2 = 1.0 - 6.0 / 31.0;
  10. double weight3 = 1.0 - 4.0 / 30.0;
  11. InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(
  12. CH_CPI, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3), weight1);
  13. InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(
  14. CH_CPI, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3), weight2);
  15. InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(
  16. CH_CPI, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3), weight3);
  17. assertEquals(test.createRateComputation(DATE_2015_02_05), obs1);
  18. assertEquals(test.createRateComputation(DATE_2015_03_07), obs2);
  19. assertEquals(test.createRateComputation(DATE_2015_04_05), obs3);
  20. }

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

  1. InflationMonthlyRateComputation.of(
  2. GB_HICP,
  3. YearMonth.from(DATE_2015_01_05).minusMonths(3),
  4. YearMonth.from(DATE_2015_02_05).minusMonths(3)))
  5. .build();
  6. RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2)
  7. InflationMonthlyRateComputation.of(
  8. GB_HICP,
  9. YearMonth.from(DATE_2015_02_05).minusMonths(3),
  10. YearMonth.from(DATE_2015_03_07).minusMonths(3)))
  11. .build();
  12. RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3)
  13. InflationMonthlyRateComputation.of(
  14. GB_HICP,
  15. YearMonth.from(DATE_2015_03_07).minusMonths(3),
  16. YearMonth.from(DATE_2015_04_05).minusMonths(3)))
  17. .build();
  18. ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA);

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

  1. } else if (dayOfMonth < 10) {
  2. weight -= (dayOfMonth + endDate.minusMonths(1).lengthOfMonth() - 10d) / endDate.minusMonths(1).lengthOfMonth();
  3. referenceEndMonth = referenceEndMonth.minusMonths(1);

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

  1. public void coverage() {
  2. HistoricPriceIndexValues instance1 = HistoricPriceIndexValues.of(US_CPI_U, VAL_DATE, USCPI_TS);
  3. coverImmutableBean(instance1);
  4. HistoricPriceIndexValues test2 =
  5. HistoricPriceIndexValues.of(
  6. GB_HICP,
  7. VAL_DATE.plusMonths(1),
  8. LocalDateDoubleTimeSeries.of(VAL_MONTH.minusMonths(2).atEndOfMonth(), 100d));
  9. coverBeanEquals(instance1, test2);
  10. }

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

  1. .rateComputation(InflationInterpolatedRateComputation.of(
  2. CH_CPI,
  3. YearMonth.from(DATE_2015_01_05).minusMonths(3),
  4. YearMonth.from(DATE_2015_02_05).minusMonths(3),
  5. weight1))
  6. .build();
  7. .rateComputation(InflationInterpolatedRateComputation.of(
  8. CH_CPI,
  9. YearMonth.from(DATE_2015_02_05).minusMonths(3),
  10. YearMonth.from(DATE_2015_03_07).minusMonths(3),
  11. weight2))
  12. .build();
  13. .rateComputation(InflationInterpolatedRateComputation.of(
  14. CH_CPI,
  15. YearMonth.from(DATE_2015_03_07).minusMonths(3),
  16. YearMonth.from(DATE_2015_04_05).minusMonths(3),
  17. weight3))
  18. .build();

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

  1. public void coverage() {
  2. SimplePriceIndexValues instance1 = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
  3. coverImmutableBean(instance1);
  4. SimplePriceIndexValues test2 =
  5. SimplePriceIndexValues.of(
  6. GB_HICP,
  7. VAL_DATE.plusMonths(1),
  8. CURVE_NOFIX,
  9. LocalDateDoubleTimeSeries.of(VAL_MONTH.minusMonths(2).atEndOfMonth(), 100d));
  10. coverBeanEquals(instance1, test2);
  11. }

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

  1. GB_HICP,
  2. 123d,
  3. YearMonth.from(DATE_2015_02_05).minusMonths(3)))
  4. .build();
  5. RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2)
  6. InflationMonthlyRateComputation.of(
  7. GB_HICP,
  8. YearMonth.from(DATE_2015_02_05).minusMonths(3),
  9. YearMonth.from(DATE_2015_03_07).minusMonths(3)))
  10. .build();
  11. RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3)
  12. InflationMonthlyRateComputation.of(
  13. GB_HICP,
  14. YearMonth.from(DATE_2015_03_07).minusMonths(3),
  15. YearMonth.from(DATE_2015_04_05).minusMonths(3)))
  16. .build();
  17. ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA);

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

  1. InflationInterpolatedRateComputation.of(
  2. GB_RPI,
  3. YearMonth.from(bda.adjust(DATE_14_06_09, REF_DATA)).minusMonths(3),
  4. YearMonth.from(bda.adjust(DATE_19_06_09, REF_DATA)).minusMonths(3),
  5. weight))
  6. .build())

相关文章