Java Programs›Date & Time

📅Java Date & Time Programs

The java.time API, introduced in Java 8, replaced the error-prone Date and Calendar classes. These programs show how to format, parse, compare and shift dates, and how to convert times correctly between zones.15 programs · each with full code, output and a step-by-step explanation

Most Asked in Interviews

🔍
Beginner
01
Add Days and Months to a Date
Shifts a date forwards and backwards with plusDays, plusMonths, plusWeeks and minusYears.
beginnerDate & Time
View Program →
02
Calculate Days Between Two Dates
Measures the gap between two dates in days and whole weeks with ChronoUnit.
beginnerDate & Time
View Program →
03
Calculate Exact Age from Date of Birth
Works out an exact age in years, months and days from a date of birth with Period, plus the next birthday.
beginnerDate & Time
View Program →
04
Calculate Time Difference Between Two Times
Measures the gap between a check-in and a check-out time with Duration and splits it into hours, minutes and seconds.
beginnerDate & Time
View Program →
05
Compare Two Dates
Checks whether a submission date is before, after or on a deadline with isBefore, isAfter and isEqual.
beginnerDate & Time
View Program →
06
Convert Epoch Time to Date
Turns a Unix timestamp in seconds into a readable UTC and Kolkata date-time, and into milliseconds.
beginnerDate & Time
View Program →
07
Find First and Last Day of a Month
Finds the first and last day of February 2028 with TemporalAdjusters, plus the month length and leap-year status.
beginnerDate & Time
View Program →
08
Find the Day of the Week for a Date
Finds the weekday for any date with LocalDate.getDayOfWeek and prints its full name.
beginnerDate & Time
View Program →
09
Format a Date
Formats one date-time several ways with DateTimeFormatter patterns such as dd/MM/yyyy and MMMM d, yyyy.
beginnerDate & Time
View Program →
10
List All Dates Between Two Dates
Prints every date from 26 February to 3 March 2026 with its weekday, crossing the month boundary correctly.
beginnerDate & Time
View Program →