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

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

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

YearMonth.plusMonths介绍

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

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 after this year/month.
  3. *
  4. * @param self a YearMonth
  5. * @param months the number of months to add
  6. * @return a Year
  7. * @since 2.5.0
  8. */
  9. public static YearMonth plus(final YearMonth self, long months) {
  10. return self.plusMonths(months);
  11. }

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

  1. /**
  2. * Returns a copy of this year-month with the specified period in months subtracted.
  3. * <p>
  4. * This instance is immutable and unaffected by this method call.
  5. *
  6. * @param monthsToSubtract the months to subtract, may be negative
  7. * @return a {@code YearMonth} based on this year-month with the months subtracted, not null
  8. * @throws DateTimeException if the result exceeds the supported range
  9. */
  10. public YearMonth minusMonths(long monthsToSubtract) {
  11. return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
  12. }

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

  1. YearMonth q2016_ymStart = YearMonth.of( 2016 , 1 ); // 2016-01
  2. YearMonth q2016_ymStop = q2016_ymStart.plusMonths( 3 ); // 2016-04 for half-open quarter.
  3. myPreparedStatement.setString( , q2016_ymStart.toString() );
  4. myPreparedStatement.setString( , q2016_ymStop.toString() );

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

  1. /**
  2. * 月の加算を実行します
  3. *
  4. * @param date
  5. * 日付型
  6. * @param months
  7. * 加算する月
  8. * @return 月を加算した結果のカレンダー
  9. */
  10. public static YearMonth addMonths(final YearMonth date, final int months) {
  11. if (date == null) {
  12. return null;
  13. }
  14. return date.plusMonths(months);
  15. }

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

  1. // TODO: Which time zone are you interested in?
  2. YearMonth yearMonth = YearMonth.now();
  3. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
  4. List<String> dates = new ArrayList<>();
  5. for (int i = 0; i < 6; i++) {
  6. dates.add(formatter.format(yearMonth.plusMonths(i)));
  7. }

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

  1. YearMonth from = YearMonth.of(2010, 10);
  2. YearMonth to = YearMonth.of(2011, 2);
  3. List<YearMonth> list = new ArrayList<> ();
  4. for (YearMonth ym = from; !ym.isAfter(to); ym = ym.plusMonths(1)) {
  5. list.add(ym);
  6. }

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

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

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

  1. // TODO: Which time zone are you interested in?
  2. YearMonth yearMonth = new YearMonth();
  3. DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMM");
  4. List<String> dates = new ArrayList<>();
  5. for (int i = 0; i < 6; i++) {
  6. dates.add(formatter.print(yearMonth.plusMonths(i)));
  7. }

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

  1. YearMonth start = YearMonth.of( 2008 , Month.OCTOBER );
  2. YearMonth stop = YearMonth.of( 2009 , Month.DECEMBER );
  3. List<YearMonth> yms = new ArrayList<>();
  4. YearMonth ym = start ;
  5. while( ! ym.isAfter( stop ) ) {
  6. yms.add( ym );
  7. // Set up the next loop.
  8. ym = ym.plusMonths( 1 );
  9. }

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

  1. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu.MM");
  2. YearMonth date = YearMonth.parse("2010.01", formatter);
  3. YearMonth end = YearMonth.parse("2010.05", formatter);
  4. while (!date.isAfter(end)) {
  5. System.out.println(date.format(formatter));
  6. date = date.plusMonths(1);
  7. }

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

  1. public static void main(String[] args) {
  2. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM-yyyy", Locale.ENGLISH);
  3. YearMonth startDate = YearMonth.parse("Jan-2015", formatter);
  4. YearMonth endDate = YearMonth.parse("Apr-2015", formatter);
  5. while(startDate.isBefore(endDate)) {
  6. System.out.println(startDate.format(formatter));
  7. startDate = startDate.plusMonths(1);
  8. }
  9. }

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

  1. YearMonth ym = ymStart;
  2. do {
  3. int daysInMonth = ym.lengthOfMonth ();
  4. String monthName = ym.getMonth ().getDisplayName ( TextStyle.FULL , Locale.CANADA_FRENCH );
  5. System.out.println ( ym + " : " + daysInMonth + " jours en " + monthName );
  6. // Prepare for next loop.
  7. ym = ym.plusMonths ( 1 );
  8. } while ( ym.isBefore ( ymStop ) );

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

  1. public static Collection<YearMonth> generateFromLocalDate(LocalDate start, LocalDate end) {
  2. YearMonth yearMonthActual = YearMonth.of(start.getYear(), start.getMonth());
  3. YearMonth yearMonthEnd = YearMonth.of(end.getYear(), end.getMonth());
  4. List<YearMonth> listYearMonthReturn = new ArrayList<>();
  5. do {
  6. listYearMonthReturn.add(yearMonthActual);
  7. yearMonthActual = yearMonthActual.plusMonths(1);
  8. } while (yearMonthActual.isBefore(yearMonthEnd));
  9. listYearMonthReturn.add(yearMonthEnd);
  10. return listYearMonthReturn;
  11. }
  12. }

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

  1. public static Collection<YearMonth> generateFromLocalDate(LocalDate start, LocalDate end) {
  2. YearMonth yearMonthActual = YearMonth.of(start.getYear(), start.getMonth());
  3. YearMonth yearMonthEnd = YearMonth.of(end.getYear(), end.getMonth());
  4. List<YearMonth> listYearMonthReturn = new ArrayList<>();
  5. do {
  6. listYearMonthReturn.add(yearMonthActual);
  7. yearMonthActual = yearMonthActual.plusMonths(1);
  8. } while (yearMonthActual.isBefore(yearMonthEnd));
  9. listYearMonthReturn.add(yearMonthEnd);
  10. return listYearMonthReturn;
  11. }
  12. }

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

  1. public void test_valuePointSensitivity_forward() {
  2. YearMonth month = VAL_MONTH.plusMonths(3);
  3. SimplePriceIndexValues test = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
  4. PriceIndexObservation obs = PriceIndexObservation.of(US_CPI_U, month);
  5. InflationRateSensitivity expected = InflationRateSensitivity.of(obs, 1d);
  6. assertEquals(test.valuePointSensitivity(obs), expected);
  7. }

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

  1. public void test_parameterSensitivity() {
  2. SimplePriceIndexValues test = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
  3. InflationRateSensitivity point =
  4. InflationRateSensitivity.of(PriceIndexObservation.of(US_CPI_U, VAL_MONTH.plusMonths(3)), 1d);
  5. assertEquals(test.parameterSensitivity(point).size(), 1);
  6. }

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

  1. public void coverage() {
  2. AbsoluteIborFutureTemplate test = AbsoluteIborFutureTemplate.of(YEAR_MONTH, CONVENTION);
  3. coverImmutableBean(test);
  4. AbsoluteIborFutureTemplate test2 = AbsoluteIborFutureTemplate.of(YEAR_MONTH.plusMonths(1), CONVENTION2);
  5. coverBeanEquals(test, test2);
  6. }

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

  1. public void coverage() {
  2. PriceIndexObservation test = PriceIndexObservation.of(GB_HICP, FIXING_MONTH);
  3. coverImmutableBean(test);
  4. PriceIndexObservation test2 = PriceIndexObservation.of(CH_CPI, FIXING_MONTH.plusMonths(1));
  5. coverBeanEquals(test, test2);
  6. }

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

  1. public void test_parameterSensitivity() {
  2. HistoricPriceIndexValues test = HistoricPriceIndexValues.of(US_CPI_U, VAL_DATE, USCPI_TS);
  3. InflationRateSensitivity point =
  4. InflationRateSensitivity.of(PriceIndexObservation.of(US_CPI_U, VAL_MONTH.plusMonths(3)), 1d);
  5. assertThrows(MarketDataNotFoundException.class, () -> test.parameterSensitivity(point));
  6. }

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

  1. public void test_valuePointSensitivity_forward() {
  2. YearMonth month = VAL_MONTH.plusMonths(3);
  3. HistoricPriceIndexValues test = HistoricPriceIndexValues.of(US_CPI_U, VAL_DATE, USCPI_TS);
  4. PriceIndexObservation obs = PriceIndexObservation.of(US_CPI_U, month);
  5. assertThrows(MarketDataNotFoundException.class, () -> test.value(obs));
  6. assertThrows(MarketDataNotFoundException.class, () -> test.valuePointSensitivity(obs));
  7. }

相关文章