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



描述

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

宣告

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

public long getLong(TemporalField field)

引數

field - 要獲取的欄位,非空。

返回值

欄位的值。

異常

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

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

  • ArithmeticException - 如果發生算術溢位

示例

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

package com.tutorialspoint;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;

public class ZonedDateTimeDemo {
   public static void main(String[] args) {
 
      ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
      System.out.println(date.getLong(ChronoField.CLOCK_HOUR_OF_DAY));  
   }
}

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

12
廣告
© . All rights reserved.