- 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 - 分割槽 ID
- 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)
引數
秒數 - 秒數,可以是正數或負數。
返回值
持續時間,非空。
異常
算術異常 - 如果輸入的秒數超出持續時間容量。
示例
以下示例展示了 java.time.Duration.ofSeconds(long seconds) 方法的用法。
package com.tutorialspoint;
import java.time.Duration;
public class DurationDemo {
public static void main(String[] args) {
Duration duration = Duration.ofSeconds(2);
System.out.println(duration.getSeconds());
}
}
讓我們編譯並執行上面的程式,它將產生以下結果 -
2
廣告