如何用 Java 獲取兩個 Instant 時間戳之間的持續時間
我們首先使用 ofEpochSeconds() 方法設定兩個 Instant,方法使用 1970-01- 01T00:00:00Z 紀元的秒數。
現在獲取上述兩個 Instant 之間的持續時間
Duration res = Duration.between(one, two);
例項
import java.time.Duration;
import java.time.Instant;
public class Demo {
public static void main(String[] args) {
Instant one = Instant.ofEpochSecond(1845836728);
Instant two = Instant.ofEpochSecond(1845866935);
Duration res = Duration.between(one, two);
System.out.println(res);
}
}輸出
PT8H23M27S
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP