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



說明

java.time.OffsetDateTime.get(TemporalField field) 方法從此日期獲取指定欄位的值,型別為 int。

宣告

以下是 java.time.OffsetDateTime.get(TemporalField field) 方法的宣告。

public int get(TemporalField field)

public int get(TemporalField field)

引數

field − 要獲取的欄位,不能為空。

返回值

欄位的值。

  • 異常

  • DateTimeException − 如果無法獲得欄位的值或該值超出欄位的有效值範圍。

  • UnsupportedTemporalTypeException − 如果該欄位不受支援或值範圍超出了 int

ArithmeticException − 如果發生數字溢位

示例

package com.tutorialspoint;

import java.time.OffsetDateTime;
import java.time.temporal.ChronoField;

public class OffsetDateTimeDemo {
   public static void main(String[] args) {
 
      OffsetDateTime date = OffsetDateTime.parse("2017-02-03T12:30:30+01:00");
      System.out.println(date.get(ChronoField.CLOCK_HOUR_OF_DAY));  
   }
}

線上示例

12
列印頁面
© . All rights reserved.