# 时间计算

# Date 转 LocalDateTime

LocalDateTime examDate = exam.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
1

# timestamp 转 LocalDateTime

LocalDateTime examDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
1

# LocalDateTime 转 Date

LocalDateTime localDateTime = LocalDateTime.now();
Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant())
1
2

# 计算耗时

Instant start = Instant.now();
// do something
Instant end = Instant.now();
Duration.between(start, end).toMinutes();
Duration.between(start, end).toMillis();
1
2
3
4
5
更新时间: 2021-06-30 22:17:08