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



描述

java.time.OffsetDateTime.getLong(TemporalField field) 方法以 long 的形式從該日期時間獲取指定欄位的值。

宣告

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

public long getLong(TemporalField field)

引數

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

返回值

欄位的值。

異常

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

  • UnsupportedTemporalTypeException − 如果不支援該欄位或值範圍超出 long。

  • ArithmeticException − 如果發生數值溢位

示例

以下示例演示了 java.time.OffsetDateTime.getLong(TemporalField field) 方法的用法。

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.getLong(ChronoField.CLOCK_HOUR_OF_DAY));  
   }
}

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

12
廣告
© . All rights reserved.