- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 即時
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - 週期
- java.time - 年
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - 時區偏移量
- java.time 包列舉
- java.time - 月份
- java.time 實用資源
- java.time - 討論
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
廣告