Modul 2 von 5 · Text
Calculation of the difference between dates
🧠 Super resumo mental
Duration → small units (hours/minutes)
Period → big units (years/months/days)
✅ Duration
Duration measures time in:
-
hours
-
minutes
-
seconds
It is used with:
-
LocalTime
-
LocalDateTime
👉 Think of Duration as clock-based time.
Example:
Duration.between(start, end);
It calculates how much time passed between two times.
✅ Period
Period measures time in:
-
years
-
months
-
days
It is used with:
-
LocalDate
👉 Think of Period as calendar-based time.
Example:
Period.between(startDate, endDate);
It calculates the difference in years, months, and days.