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



描述

java.time.LocalTime.getLong(TemporalField field) 方法從該時間獲取指定欄位的值(以長整型形式表示)。

宣告

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

public long getLong(TemporalField field)

引數

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

返回值

欄位的值。

異常

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

  • UnsupportedTemporalTypeException - 如果不支援該欄位或值範圍超出長整型。

  • ArithmeticException - 如果發生數字溢位

示例

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

package com.tutorialspoint;

import java.time.LocalTime;
import java.time.temporal.ChronoField;

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

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

12
廣告
© . All rights reserved.