java.time.YearMonth.getMonthValue()方法

java.time.YearMonth.getMonthValue()方法獲取月份字段112之間的值。

聲明

以下是java.time.YearMonth.getMonthValue()方法的聲明。

public int getMonthValue()

返回值

月份值,從112

示例

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

package com.zaixian;

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

上一篇: java.time.YearMonth類 下一篇: java.time.ZonedDateTime類