📅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
View Program →Add Days and Months to a Date
Shifts a date forwards and backwards with plusDays, plusMonths, plusWeeks and minusYears.
beginnerDate & Time
02
View Program →Calculate Days Between Two Dates
Measures the gap between two dates in days and whole weeks with ChronoUnit.
beginnerDate & Time
03
View Program →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
04
View Program →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
05
View Program →Compare Two Dates
Checks whether a submission date is before, after or on a deadline with isBefore, isAfter and isEqual.
beginnerDate & Time
06
View Program →Convert Epoch Time to Date
Turns a Unix timestamp in seconds into a readable UTC and Kolkata date-time, and into milliseconds.
beginnerDate & Time
07
View Program →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
08
View Program →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
09
View Program →Format a Date
Formats one date-time several ways with DateTimeFormatter patterns such as dd/MM/yyyy and MMMM d, yyyy.
beginnerDate & Time
10
View Program →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
Intermediate
11
View Program →Add Business Days to a Date
Calculates a delivery date five business days after an order, skipping Saturdays and Sundays.
intermediateDate & Time
12
View Program →Convert Date to LocalDate
Converts a legacy java.util.Date to a LocalDate and back, showing why the time zone matters for the calendar date.
intermediateDate & Time
13
View Program →Convert Time Between Time Zones
Shows one meeting time as the local clock time in Kolkata, London, New York and Tokyo.
intermediateDate & Time
14
View Program →Parse a Date String
Turns date text into LocalDate objects and shows how lenient and strict parsing treat an impossible date.
intermediateDate & Time
15
View Program →Print a Monthly Calendar
Prints March 2026 as a Monday-first calendar grid, placing the 1st under the correct weekday.
intermediateDate & Time