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



描述

java.time.Month.from(TemporalAccessor temporal) 方法從一個時間物件中獲取 Month 的例項。

宣告

以下是 java.time.Month.from(TemporalAccessor temporal) 方法的宣告。

public static Month from(TemporalAccessor temporal)

public static Month from(TemporalAccessor temporal)

引數

temporal - 要轉換的、非空的時間物件。

返回值

本地日期,非空。

異常

DateTimeException - 如果無法轉換為月份。

示例

package com.tutorialspoint;

import java.time.Month;
import java.time.ZonedDateTime;

public class MonthDemo {
   public static void main(String[] args) {
 
      Month day = Month.from(ZonedDateTime.now());
      System.out.println(day);  
   }
}

動態演示

DECEMBER
列印頁面
© . All rights reserved.