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



說明

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

宣告

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

public Month getMonth()

返回值

月份,不能為空。

示例

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

package com.tutorialspoint;

import java.time.MonthDay;

public class MonthDayDemo {
   public static void main(String[] args) {
 
      MonthDay date = MonthDay.parse("--12-30");
      System.out.println(date.getMonth());  
   }
}

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

DECEMBER
廣告