java.time.YearMonth.getMonthValue() 方法示例



說明

java.time.YearMonth.getMonthValue() 方法獲取 1 到 12 之間的年月欄位。

宣告

以下是 java.time.YearMonth.getMonthValue() 方法的宣告。

public int getMonthValue()

返回值

年月,從 1 到 12。

示例

以下示例演示了 java.time.YearMonth.getMonthValue() 方法的使用。

package com.tutorialspoint;

import java.time.YearMonth;

public class YearMonthDemo {
   public static void main(String[] args) {
 
      YearMonth date = YearMonth.of(2017,12);
      System.out.println(date.getMonthValue());  
   }
}

讓我們編譯並執行以上程式,這會產生以下結果 −

12
廣告
© . All rights reserved.