Java 程式獲取兩個時間戳之間的持續時間
建立兩個時間戳
Instant time1 = Instant.now(); Instant time2 = Instant.now().plusSeconds(50);
使用 between() 獲取兩個時間戳之間的持續時間
long resMilli = Duration.between(time1, time2).toMillis();
示例
import java.time.Duration;
import java.time.Instant;
public class Demo {
public static void main(String[] args) {
Instant time1 = Instant.now();
Instant time2 = Instant.now().plusSeconds(50);
long resMilli = Duration.between(time1, time2).toMillis();
System.out.println("Duration between two time intervals = "+resMilli);
}
}輸出
Duration between two time intervals = 50000
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP