java.time.LocalDate Class in Java

Last Updated : 14 Jul, 2026

The LocalDate class, available in the java.time package, represents a date without time and timezone. Introduced in Java 8, it is part of the modern Date-Time API and is commonly used to store and manipulate dates such as birthdays, holidays, and event dates.

  • Does not store time or timezone information.
  • Immutable and thread-safe.
  • Supports date arithmetic such as adding or subtracting days, months, and years.

Syntax

public final class LocalDate
extends Object
implements Temporal,
TemporalAdjuster,
ChronoLocalDate,
Serializable

Commonly Used Methods of LocalDate

Methods

Description

adjustInto(Temporal temporal)This method adjusts the specified temporal object to having the same date as this object.
 atStartOfDay()This method combines this date with the time of midnight to create a LocalDateTime at the start of this date.
atStartOfDay(ZoneId zone)This method returns a zoned date-time from this date at the earliest valid time according to the rules in the time-zone.
 atTime(int hour, int minute)This method combines this date with a time to create a LocalDateTime.
 atTime(int hour, int minute, int second)This method combines this date with a time to create a LocalDateTime.
 compareTo(ChronoLocalDate other)This method compares this date to another date.
equals(Object obj)This method checks if this date is equal to another date.
format(DateTimeFormatter formatter)This method formats this date using the specified formatter.
from(TemporalAccessor temporal)This method obtains an instance of LocalDate from a temporal object.
 get(TemporalField field)This method gets the value of the specified field from this date as an int.
 getChronology()This method gets the chronology of this date, which is the ISO calendar system.
getDayOfMonth()This method gets the day-of-month field.
 getDayOfWeek()This method gets the day-of-week field, which is an enum DayOfWeek.
getDayOfYear()This method gets the day-of-year field.
 getEra()This method gets the era applicable at this date.
getLong(TemporalField field)This method gets the value of the specified field from this date as a long.
getMonth()This method gets the month-of-year field using the Month enum.
getMonthValue()This method gets the month-of-year field from 1 to 12.
 getYear()This method gets the year field.
hashCode()A hash code for this date.
isAfter(ChronoLocalDate other)This method checks if this date is after the specified date.
isBefore(ChronoLocalDate other)This method checks if this date is before the specified date.
isEqual(ChronoLocalDate other)This method checks if this date is equal to the specified date.
isLeapYear()This method checks if the year is a leap year, according to the ISO proleptic calendar system rules.
isSupported(TemporalField field)This method checks if the specified field is supported.
lengthOfMonth()This method returns the length of the month represented by this date.
lengthOfYear()This method returns the length of the year represented by this date.
now() It is a method used to return the instance of LocalDateTime class.
ofPattern()It is a method used with DateTimeFormatter to format and parse date and time. It accepts all types or sorts of value, to display in a different format.
query(TemporalQuery<R> query)This method queries this date using the specified query.
range(TemporalField field)This method gets the range of valid values for the specified field.
 toEpochDay()This method converts this date to Epoch Day.
withDayOfMonth(int dayOfMonth)This method returns a copy of this LocalDate with the day-of-month altered.
withDayOfYear(int dayOfYear)This method returns a copy of this LocalDate with the day-of-year altered.
 withMonth(int month)This method returns a copy of this LocalDate with the month-of-year altered.
 withYear(int year)This method returns a copy of this LocalDate with the year altered.

Approach

  • Import the required classes from the java.time package.
  • Create or obtain a LocalDate object using methods such as now(), of(), or parse().
  • Perform operations such as formatting, comparison, or date modification using the available methods.
  • Display the resulting date using System.out.println().

Below is the implementation of the problem statement:

Example 1: Display the Current Date

Java
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Geeks {

    public static void main(String[] args) {

        // Get the current date
        LocalDate date = LocalDate.now();

        // Format the date
        DateTimeFormatter formatter =
                DateTimeFormatter.ofPattern("dd MMM yyyy");

        System.out.println("Current Date: "
                + date.format(formatter));
    }
}

Output
Current Date: 09 Jul 2026

Explanation: The LocalDate.now() method returns the current system date. The DateTimeFormatter formats the date into a more readable format before displaying it.

Example 2: Modify an Existing Date

Java
import java.time.LocalDate;

public class Geeks {

    public static void main(String[] args) {

        LocalDate date = LocalDate.parse("2026-07-09");

        LocalDate updatedDate = date.withDayOfYear(1);

        System.out.println(updatedDate);
    }
}

Output
2026-01-01

Explanation: The withDayOfYear() method returns a new LocalDate with the specified day of the year while keeping the original object unchanged.

Advantages of LocalDate

  • Represents dates without time and timezone.
  • Immutable and thread-safe.
  • Easy to create, compare, and manipulate dates.
  • Supports parsing and formatting using DateTimeFormatter.
  • Provides rich methods for date calculations.
  • Replaces the legacy java.util.Date API with a cleaner design.
  • Suitable for applications such as birthdays, anniversaries, and scheduling.
Comment