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



說明

java.time.YearMonth.of(int year, int month) 方法從年和月獲取一個 YearMonth 例項。

宣告

以下是 java.time.YearMonth.of(int year, int month) 方法的宣告。

public static YearMonth of(int year,int month)

引數

  • year - 表示的年份,從 MIN_YEAR 到 MAX_YEAR。

  • month - 表示的年份中的月份,從 1(一月)到 12(十二月)。

返回值

非空的 YearMonth。

異常

DateTimeException - 如果任一欄位值無效。

示例

以下示例顯示了 java.time.YearMonth.of(int years, int months) 方法的用法。

package com.tutorialspoint;

import java.time.YearMonth;

public class YearMonthDemo {
   public static void main(String[] args) {

      YearMonth year = YearMonth.of(2017,12);
      System.out.println(year);     
   }
}

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

2017-12
廣告
© . All rights reserved.