- java.time 程式包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 即刻
- java.time - 本地日期
- java.time - 本地日期時間
- java.time - 本地時間
- java.time - 月日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 週期
- java.time - 年
- java.time - 年月
- java.time - 區域化日期時間
- java.time - 區域標識
- java.time - 區域偏移
- java.time 程式包列舉
- java.time - 月
- java.time 有用資源
- java.time - 討論
java.time.Duration.ofSeconds() 方法示例
說明
java.time.Duration.ofSeconds(long seconds) 方法獲取表示秒數和納秒調整時長的持續時間。
宣告
以下是 java.time.Duration.ofSeconds(long seconds) 方法的宣告。
public static Duration ofSeconds(long seconds, long nanoAdjustment)
引數
seconds - 秒數,為正數或負數。
nanoAdjustment - 秒數的納秒調整,為正數或負數。
返回值
Duration,非空。
異常
ArithmeticException - 如果調整導致秒數超過 Duration 的容量。
示例
以下示例顯示 java.time.Duration.ofSeconds(long seconds, long nanoAdjustment) 方法的用法。
package com.tutorialspoint;
import java.time.Duration;
public class DurationDemo {
public static void main(String[] args) {
Duration duration = Duration.ofSeconds(2);
Duration duration1 = duration.plus(Duration.ofSeconds(5));
System.out.println(duration1.toMillis());
}
}
讓我們編譯並執行上述程式,這將產生以下結果 -
7000
廣告