让我们首先ofEpochSeconds()
使用从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