當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java java.time.YearMonth.of()用法及代碼示例


描述

這個java.time.YearMonth.of(int year,Month month)方法從年和月中獲取 YearMonth 的實例。

聲明

以下是聲明java.time.YearMonth.of(int year,Month month)方法。

public static YearMonth of(int year,Month month)

參數

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

  • month− 表示的 month-of-year。

返回值

一個 YearMonth,不為空。

異常

DateTimeException− 如果年份值無效。

示例

下麵的例子展示了 java.time.YearMonth.of(int years,int Month) 方法的用法。

package com.tutorialspoint;

import java.time.Month;
import java.time.YearMonth;

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

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

讓我們編譯並運行上麵的程序,這將產生以下結果 -

2017-12

相關用法


注:本文由純淨天空篩選整理自 java.time.YearMonth.of() Method Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。