프로그래밍/JAVA
[Java] LocalDate, LocalDateTime 날짜 차이 계산
Gooding
2022. 11. 11. 20:12
728x90
반응형
LocalDate 날짜 차이 계산하기
Period
LocalDate startDate = LocalDate.of(2020, 11, 10);
LocalDate endDate = LocalDate.of(2022, 11, 20);
Period period = Period.between(startDate, endDate);
log.debug("Days : {}", period.getDays());
// Days : 10
LocalDateTime 날짜 차이 계산하기
ChronoUnit
Duration과 Period 객체를 생성하지 않고 특정 시간 단위로 차이를 구하는 방법
LocalDateTime startDateTime = LocalDateTime.of(2020, 12, 20, 9, 30, 30);
LocalDateTime endDateTime = LocalDateTime.of(2022, 12, 20, 10, 0, 40);
log.debug("Days: {}", ChronoUnit.DAYS.between(startDateTime, endDateTime));
// Days: 730
반응형