Contents
주요 특징ChronoUnit은 Java 8에서 도입된java.time 패키지 의 일부로, 날짜와 시간 간의 차이를 특정 시간 단위로 계산하거나, 특정 시간 단위만큼 날짜나 시간을 더하거나 빼는 데 사용되는 열거형(enum)입니다.
이는 기존의 java.util.Date 및 java.util.Calendar 보다 더 직관적이고 사용하기 쉬운 API를 제공합니다.
주요 특징
- 시간 단위 제공: ChronoUnit은 다양한 시간 단위를 제공합니다. 예:
- TemporalUnit 인터페이스 구현: ChronoUnit은
TemporalUnit
인터페이스를 구현하며, 이를 통해 날짜와 시간 객체를 조작하거나 차이를 계산할 수 있습니다
package ex04;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class Chrono01 {
public static void main(String[] args) {
LocalDateTime writeTime = LocalDateTime.of(2025, 02, 11, 10, 3);
LocalDateTime nowTime = LocalDateTime.now();
long daysBetween = ChronoUnit.DAYS.between(nowTime, writeTime);
long hoursBetween = ChronoUnit.HOURS.between(nowTime, writeTime);
long minsBetween = ChronoUnit.MINUTES.between(nowTime, writeTime);
System.out.println(daysBetween + "일전");
System.out.println(hoursBetween + "시간 전");
System.out.println(minsBetween + "분전");
}
}

Share article