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



說明

**java.time.Month.of(String month)** 方法從 int 值獲取 Month 的例項。

宣告

以下是 **java.time.Month.of(String month)** 方法的宣告。

public static Month of(String month)

public static Month of(String month)

引數

**month** - 要表示的月份,從 1(1 月)到 12(12 月)

返回值

月份,非空。

異常

**DateTimeException** - 如果月份無效。

示例

package com.tutorialspoint;

import java.time.Month;

public class MonthDemo {
   public static void main(String[] args) {
 
      Month month = Month.of(3);
      System.out.println(month);  
   }
}

現場演示

MARCH
列印本頁
© . All rights reserved.