
- java.time 程式包類
- java.time - 主頁
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 程式包列舉
- java.time - Month
- java.time 有用資源
- java.time - 討論
java.time.Period.plusMonths() 方法示例
說明
java.time.Period.plusMonths(long months) 方法返回此週期加上指定週期的週期副本(按月)。
宣告
以下是 java.time.Period.plusMonths(long months) 方法的宣告。
public Period plusMonths(long months)
引數
months - 要新增的月份,為正數或負數。
返回值
基於此週期加上指定週期的週期,不為 null。
異常
ArithmeticException - 如果發生數字溢位。
示例
以下示例展示了 java.time.Period.plusMonths(long months) 方法的使用方法。
package com.tutorialspoint; import java.time.Period; public class PeriodDemo { public static void main(String[] args) { Period period = Period.ofMonths(2); Period period1 = period.plusMonths(1); System.out.println(period1.getMonths()); } }
讓我們編譯並執行以上程式,將得到以下結果 -
3
廣告