forked from nibnait/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalDateTimeUtil.java
More file actions
32 lines (26 loc) · 889 Bytes
/
LocalDateTimeUtil.java
File metadata and controls
32 lines (26 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package common.util;
import lombok.Data;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class LocalDateTimeUtil {
public static void main(String[] args) {
LocalDateTime start = LocalDateTime.now().minusMinutes(1);
LocalDateTime end = LocalDateTime.now();
TimeBetween timeBetween = calcTimeBetween(start, end);
System.out.println(timeBetween.toString());
}
@Data
static class TimeBetween{
private long days;
private long seconds;
}
/**
* 计算时间差
*/
public static TimeBetween calcTimeBetween(LocalDateTime start, LocalDateTime end) {
TimeBetween timeBetween = new TimeBetween();
timeBetween.setDays(ChronoUnit.DAYS.between(start, end));
timeBetween.setSeconds(ChronoUnit.SECONDS.between(start, end));
return timeBetween;
}
}