← Back to Week 3 Hub

LocalDate / LocalTime / LocalDateTime

Three date-and-time types from java.time. Each one holds a different piece of the puzzle — pick the one that fits your data.

Java 8 made dates easy. Before Java 8, working with dates was painful. The java.time package introduced LocalDate, LocalTime, and LocalDateTime — clean, immutable, easy to read.
LocalDate
date only
Year, month, day. No time component. Format: YYYY-MM-DD (ISO 8601).
Good for: birthdays, due dates, holidays — anything that doesn't need a clock time.
LocalTime
time only
Hours, minutes, seconds, nanoseconds. No date component.
Good for: store closing time, daily alarm, class start time — times that repeat every day.
LocalDateTime
date + time
Both a date and a time in one object. Format: YYYY-MM-DDTHH:mm:ss.
Good for: timestamps, appointments, deposit times — any specific moment.
Date & Time Parts Explorer

LocalDate parts

.getYear()
.getMonth()
.getMonthValue()
.getDayOfMonth()
.getDayOfWeek()
.getDayOfYear()

LocalTime parts

.getHour()
.getMinute()
.getSecond()
.getNano()
toString() value:

Which type fits? Quick decision guide

🎂 Store a customer's birthday
LocalDate
No time of day needed.
🕐 Store's closing time (9:00 PM every day)
LocalTime
Same time daily, no date tied to it.
📄 Timestamp on a bank deposit
LocalDateTime
Exact moment — date and time.
📅 A library book's due date
LocalDate
Just the calendar day.
📅 A dentist appointment
LocalDateTime
Specific day at a specific time.
⏰ A reminder at 7:30 AM daily
LocalTime
Time repeats — no specific date.

Tip: change the date or time inputs above and watch the parts update. Every getter returns exactly what its name says — no surprises.

← FileWriter vs BufferedWriter DateTimeFormatter Playground →