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



描述

java.time.LocalDateTime.getLong(TemporalField field) 方法從該日期時間獲取指定欄位的 long 型別值。

宣告

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

public long getLong(TemporalField field)

引數

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

返回值

欄位的值。

異常

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

  • UnsupportedTemporalTypeException − 如果欄位不受支援,或者值範圍超出了 long 型別。

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

示例

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

package com.tutorialspoint;

import java.time.LocalDateTime;
import java.time.temporal.ChronoField;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.parse("2017-02-03T12:30:30");
      System.out.println(date.getLong(ChronoField.CLOCK_HOUR_OF_DAY));  
   }
}

編譯並執行以上程式,它將產生以下結果 −

12
廣告
© . All rights reserved.