获取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;
}
posted @ 2021-11-16 09:52  入门小郑  阅读(52)  评论(0编辑  收藏  举报