Duration類ofHours()方法
- ofHours() 方法可在
java.time
包。 - ofHours() 方法用於表示此 Duration 中的給定小時數。
- ofHours() 方法是一個靜態方法,它可以通過類名訪問,如果我們嘗試使用類對象訪問該方法,那麽我們不會得到錯誤。
- ofHours() 方法可能會在表示小時的時間拋出異常。
算術異常:當給定的小時值超過此 Duration 的長度時,可能會拋出此異常。
用法:
public static Duration ofHours(long hrs_val);
參數:
long hrs_val
– 表示價值的小時數。
返回值:
這個方法的返回類型是Duration
,它返回保存給定小時值的 Duration。
例:
// Java program to demonstrate the example
// of ofHours(long hrs_val) method of Duration
import java.time.*;
public class OfHoursOfDuration {
public static void main(String args[]) {
long hrs_val = 3;
// returns the Duration that holds the value of the given
// argument i.e. here we are representing
// 3 hrs (3H) in this Duration du
Duration du = Duration.ofHours(hrs_val);
// Display du
System.out.println("Duration.ofHours(3):" + du);
}
}
輸出
Duration.ofHours(3):PT3H
相關用法
- Java Duration ofHours(long)用法及代碼示例
- Java Duration ofSeconds(long)用法及代碼示例
- Java Duration ofMinutes(long)用法及代碼示例
- Java Duration ofMillis(long)用法及代碼示例
- Java Duration ofMillis()用法及代碼示例
- Java Duration ofDays()用法及代碼示例
- Java Duration of()用法及代碼示例
- Java Duration ofSeconds(long, long)用法及代碼示例
- Java Duration ofSeconds()用法及代碼示例
- Java Duration ofDays(long)用法及代碼示例
- Java Duration ofNanos()用法及代碼示例
- Java Duration of(long, TemporalUnit)用法及代碼示例
- Java Duration ofMinutes()用法及代碼示例
- Java Duration ofNanos(long)用法及代碼示例
- Java Duration compareTo()用法及代碼示例
- Java Duration dividedBy()用法及代碼示例
- Java Duration minusMillis(long)用法及代碼示例
- Java Duration plus(Duration)用法及代碼示例
- Java Duration plus(long, TemporalUnit)用法及代碼示例
- Java Duration subtractFrom(Temporal)用法及代碼示例
注:本文由純淨天空篩選整理自 Java Duration Class | ofHours() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。