获取json化的时间相差的秒
作者:互联网
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* 期间
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return {@link String}
*/
private long duration(Date startTime, Date endTime) {
Instant startInstant = startTime.toInstant();
Instant endInstant = endTime.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime start = startInstant.atZone(zoneId).toLocalDateTime();
LocalDateTime end = endInstant.atZone(zoneId).toLocalDateTime();
long minutes = Duration.between(start, end).toMinutes();
return minutes * 60;
}
标签:相差,java,zoneId,获取,json,Instant,time,import,ZoneId 来源: https://www.cnblogs.com/13438145925xiaozheng/p/15559704.html