
- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 立即
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - 週期
- java.time - 年
- java.time - 年月
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 討論
java.time.YearMonth.plusMonths() 方法示例
說明
java.time.YearMonth.plusMonths(long months) 方法返回加上了指定月份的本 YearMonth 的副本。
宣告
以下是 java.time.YearMonth.plusMonths(long months) 方法的宣告。
public YearMonth plusMonths(long months)
引數
months− 要新增的月份數,可以為正數或負數。
返回值
基於此 YearMonth 且已新增指定月份的 YearMonth,不為 null。
異常
ArithmeticException− 如果發生數字溢位。
示例
以下示例演示了 java.time.YearMonth.plusMonths(long months) 方法的用法。
package com.tutorialspoint; import java.time.YearMonth; public class YearMonthDemo { public static void main(String[] args) { YearMonth date = YearMonth.parse("2017-12"); YearMonth date1 = date.plusMonths(10); System.out.println(date1); } }
讓我們編譯並執行上述程式,它將產生以下結果 −
2018-10
廣告