Duration類ofNanos()方法
- ofNanos() 方法可在
java.time
包。 - ofNanos() 方法用於表示此 Duration 中給定的納秒值。
- ofNanos() 方法是一個靜態方法,它可以通過類名訪問,如果我們嘗試使用類對象訪問該方法,那麽我們不會得到錯誤。
- ofNanos() 方法在表示納秒時可能會拋出異常。
算術異常:當給定的納秒值超過此 Duration 的長度時,可能會拋出此異常。
用法:
public static Duration ofNanos(long nanos_val);
參數:
long nanos_val
– 表示值的納秒數。
返回值:
這個方法的返回類型是Duration
,它返回保存給定納秒值的 Duration。
例:
// Java program to demonstrate the example
// of ofNanos(long nanos_val) method of Duration
import java.time.*;
public class OfNanosOfDuration {
public static void main(String args[]) {
long nanos_val = 59990000;
// returns the Duration that holds
// the value of the given argument i.e.
// here we are representing
// nanoseconds in standard seconds in
// this Duration du
Duration du = Duration.ofNanos(nanos_val);
// Display du
System.out.println("Duration.ofNanos(nanos_val):" + du);
}
}
輸出
Duration.ofNanos(nanos_val):PT0.05999S
相關用法
- Java Duration ofNanos(long)用法及代碼示例
- Java Duration ofSeconds(long)用法及代碼示例
- Java Duration ofMinutes(long)用法及代碼示例
- Java Duration ofMillis(long)用法及代碼示例
- Java Duration ofMillis()用法及代碼示例
- Java Duration ofDays()用法及代碼示例
- Java Duration ofHours()用法及代碼示例
- Java Duration of()用法及代碼示例
- Java Duration ofSeconds(long, long)用法及代碼示例
- Java Duration ofSeconds()用法及代碼示例
- Java Duration ofDays(long)用法及代碼示例
- Java Duration ofHours(long)用法及代碼示例
- Java Duration of(long, TemporalUnit)用法及代碼示例
- Java Duration ofMinutes()用法及代碼示例
- 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 | ofNanos() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。