如何用 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