如何在Java中获得两个即时时间戳之间的秒和分钟
以下是两个即时时间戳:
Instant one = Instant.ofEpochSecond(1355836728); Instant two = Instant.ofEpochSecond(1355866935);
获取两个瞬发之间的持续时间:
Duration res = Duration.between(one, two);
现在,获取两个时间戳之间的秒数:
long seconds = res.getSeconds();
现在,获取两个时间戳之间的分钟:
long minutes = res.abs().toMinutes();
示例
import java.time.Duration;
import java.time.Instant;
public class Demo {
public static void main(String[] args) {
Instant one = Instant.ofEpochSecond(1355836728);
Instant two = Instant.ofEpochSecond(1355866935);
Duration res = Duration.between(one, two);
System.out.println(res);
long seconds = res.getSeconds();
System.out.println("Seconds between Durations = "+seconds);
long minutes = res.abs().toMinutes();
System.out.println("Minutes between Durations = "+minutes);
}
}输出结果
PT8H23M27S Seconds between Durations = 30207 Minutes between Durations = 503
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短