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



說明

java.time.MonthDay.of(int 月份, int 月中天數) 方法獲得 MonthDay 例項。

宣告

以下是 java.time.MonthDay.of(int 月份, int 月中天數) 方法的宣告。

public static MonthDay of(int month, int dayOfMonth)

引數

  • 月份 − 要表示的年份中的月份,從 1(1 月)到 12(12 月)。

  • 月中天數 − 要表示的月份中的天數,從 1 到 31

返回值

月份天數,非空。

異常

DateTimeException − 如果任何欄位的值超出範圍,或如果月中天數對於月份無效。

示例

以下示例展示了 java.time.MonthDay.of(int 月份, int 月中天數) 方法的用法。

package com.tutorialspoint;

import java.time.MonthDay;

public class MonthDayDemo {
   public static void main(String[] args) {
 
      MonthDay date = MonthDay.of(6,30);
      System.out.println(date);  
   }
}

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

--06-30
廣告
© . All rights reserved.