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



描述

java.time.YearMonth.getMonth() 方法使用 Month 列舉獲取年中月份欄位。

宣告

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

public Month getMonth()

返回值

年中月份,非空。

示例

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

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.getMonth());  
   }
}

讓我們編譯並執行以上程式,將生成以下結果 −

DECEMBER
廣告
© . All rights reserved.