java.time.Period.ofMonths() 方法示例



說明

java.time.Period.ofMonths(int months) 方法獲取代表指定月數的 Period。

宣告

以下是 java.time.Period.ofMonths(int months) 方法的宣告。

public static Period ofMonths(int months)

引數

months - 月數,正數或負數。

返回值

月數的 Period,非空。

示例

以下示例演示了 java.time.Period.ofMonths(int months) 方法的用法。

package com.tutorialspoint;

import java.time.Period;

public class PeriodDemo {
   public static void main(String[] args) {

      Period period = Period.ofMonths(2);
      System.out.println(period.getMonths());      
   }
}

讓我們編譯並執行如上程式,將產生以下結果:

2
廣告
© . All rights reserved.