java.time.LocalDate.get() 方法示例



說明

java.time.LocalDate.get(TemporalField 欄位) 方法從該日期中以 int 的形式獲取指定欄位的值。

宣告

以下是 java.time.LocalDate.get(TemporalField 欄位) 方法的宣告。

public int get(TemporalField field)

引數

field - 要獲取的欄位,非空。

返回值

欄位的值。

異常

  • DateTimeException - 如果無法獲取欄位的值,或者值超出欄位的有效值範圍。

  • UnsupportedTemporalTypeException - 如果不支援該欄位,或者值範圍超出 int。

  • ArithmeticException - 如果發生數字溢位。

示例

以下示例展示了 java.time.LocalDate.get(TemporalField 欄位) 方法的用法。

package com.tutorialspoint;

import java.time.LocalDate;
import java.time.temporal.ChronoField;

public class LocalDateDemo {
   public static void main(String[] args) {
	  
      LocalDate date = LocalDate.parse("2017-02-03");
      System.out.println(date.get(ChronoField.DAY_OF_MONTH));  
   }
}

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

3
廣告