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



描述

java.time.OffsetTime.getLong(TemporalField field) 方法根據給定的欄位獲取相應的時間,並以長整形的形式返回。

宣告

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

public long getLong(TemporalField field)

引數

field - 待獲取的欄位,不可為 null。

返回值

欄位值。

異常

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

  • UnsupportedTemporalTypeException - 如果欄位不受支援或值範圍超出了長整數範圍。

  • ArithmeticException - 如果發生了數值溢位

示例

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

package com.tutorialspoint;

import java.time.OffsetTime;
import java.time.temporal.ChronoField;

public class OffsetTimeDemo {
   public static void main(String[] args) {
 
      OffsetTime time = OffsetTime.parse("12:30:30+01:00");
      System.out.println(time.getLong(ChronoField.CLOCK_HOUR_OF_DAY));  
   }
}

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

12
廣告
© . All rights reserved.