LocalDate

The java.time.LocalDate class represents a date without time (year, month, day) in the ISO-8601 calendar system. It does not include time or timezone information.

Commonly Used Methods

Simple Program

import java.time.LocalDate;

public class SimpleLocalDateExample {
    public static void main(String[] args) {
        LocalDate today = LocalDate.now();
        LocalDate independenceDay = LocalDate.of(1947, 8, 15);

        System.out.println("Today's date: " + today);
        System.out.println("Indian Independence Day: " + independenceDay);
        System.out.println("Day of the week for Independence Day: " + independenceDay.getDayOfWeek());
    }
}

Problem Statement

Paani and Mahesh are building a customer onboarding system for LoanTrust Bank. The system needs to:

  • Capture the customer’s date of birth.
  • Calculate the current age using LocalDate and Period.
  • Determine if the applicant is eligible for an adult loan (age ≥ 21).
import java.time.LocalDate;
import java.time.Period;
import java.util.Scanner;

public class CustomerOnboarding {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Input customer date of birth
        System.out.print("Enter your date of birth (yyyy-mm-dd): ");
        String dobInput = scanner.nextLine();

        LocalDate dob = LocalDate.parse(dobInput);
        LocalDate today = LocalDate.now();

        System.out.println("Date of Birth: " + dob);
        System.out.println("Today's Date: " + today);

        // Calculate age
        Period age = Period.between(dob, today);
        System.out.println("You are " + age.getYears() + " years old.");

        // Eligibility check
        if (age.getYears() >= 21) {
            System.out.println("You are eligible for an adult loan.");
        } else {
            System.out.println("You are not eligible. Must be at least 21 years old.");
        }

        scanner.close();
    }
}

/*Enter your date of birth (yyyy-mm-dd): 2003-05-20
Date of Birth: 2003-05-20
Today's Date: 2025-05-22
You are 22 years old.
You are eligible for an adult loan.
*/

The LocalDate class is one of the most frequently used types in Java for:

  • Representing dates without time or time zones.
  • Performing age calculations, determining anniversaries, or validating loan eligibility.
  • Seamless integration with Period makes it excellent for date-difference calculations.

Use LocalDate when you only need the year, month, and day component of a date, especially in applications like HR systems, banking, insurance, and education platforms.

Scroll to Top