← All Exercises

Java Date-Time API

intermediatejava~15min

Background

The java.time package (Java 8+) replaces the legacy Date and Calendar with an immutable, comprehensive date-time API.

Problem

Write a Java method that calculates the number of days between two dates using LocalDate and ChronoUnit.

Input

Two date strings in YYYY-MM-DD format.

Output

The number of days between the two dates (absolute value).

Sample tests

Sample 1

Input: "2025-01-01", "2025-01-10"
Expected: 9

Your solution

Learning objective

Learn LocalDate parsing, ChronoUnit for date arithmetic, and the modern java.time API.