Java LocalDate Class

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

Overview

Java is a simple, object-oriented, robust, platform-independent, concurrent and secure programming language for application development developed by James Gosling. The java.time.LocalDate class in Java is used for representing the current date and time depending on the location.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Introduction to Java LocalDate

LocalDate is an immutable, thread-safe class that represents Date with the default format of yyyy-MM-dd.

  • Immutability: all new Date Time APIs are immutable and also good for multithreaded environments.
  • Clarity: all functions in same place like now(), format() and parse().
  • Utility operations: the new Date Time API comes with methods that perform common tasks.

Declaration

The java.time.LocalDate class is declared as follows:

Fields for Java LocalDate (Table Format With Description for Each)

Following are the fields for class java.time.LocalDate:

  • static LocalDate MAX- the LocalDate maximum supported, '+999999999-12-31'.
  • static LocalDate MIN- the LocalDate minimum supported, '-999999999-01-01'.

Fields Details

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

MIN

The minimum supported LocalDate, -999999999-01-01. This can be used by an application as a "far past" date.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

MAX

The maximum supported LocalDate is +999999999-12-31. This can be used by an application as a "far future" date.

Methods of Java LocalDate (Table Format With Description for Each)

Important methods of LocalDate class:

Method nameMethod description
now()Obtains the current date from the system clock in the default time zone.
of(int year, Month month, int dayOfMonth)Obtains an instance of from a year, month and day.
of(int year, Month month, int dayOfMonth)Obtains an instance of from a year, month and day.
getDayOfMonth()Gets the day of month field
getMonth()Gets the month of year field using the month enum
getMonthValue()Gets the month of year field from 1 to 12
getYear()Gets the year field
isLeapYear()Checks if the year is a leap year
plusDays(long)/minusDays(long)Returns a copy of this with the specified number of days added/subtracted
plusMonth(long)/minusMonths(long)Returns a copy of this with the specified number of months added/subtracted
plusWeek(long)/minusWeeks(long)Returns a copy of this with the specified number of weeks added/subtracted
plusYears(long)/minusYears(long)Returns a copy of this with the specified number of years added/subtracted
LocalDateTime atTime(int hour, int minute)It is used for combining date with time.
int compareTo(ChronoLocalDate other)It is used for comparing two dates.
boolean equals(Object obj)It is used to check if dates are equal or not.
String format(DateTimeFormatter formatter)It is used to format the date in a specified formatter
static LocalDate parse(CharSequence text)It is used for obtaining the instance of LocalDate from a string, for instance, 2007-12-03
static LocalDate parse(CharSequence text, DateTimeFormatter formatter)It is used for obtaining the instance of LocalDate from a string by using a specified formatter

Java LocalDate Class Examples

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Example 1

Write a Java program to demonstrate LocalDate functions

Output:

Explanation: In this example, the date is displayed in the form of local date format by using the method LocalDate.of().

Example 2

Write a Java program to demonstrate LocalDate functions

Output:

Explanation: In this example, a series of methods are performed on the current date. This is to show you how different methods work.

Example 3

Write a Java program to demonstrate LocalDate functions

Output:

Explanation: In this example, the current date is stored in the variable date. The minusDays(1) operation is performed on the date variable and is stored inside yesterday's variable. This function -1 from the current date. For tomorrow’s date, +1 is addetoin the current date and is printed as tomorrow’s date.

Example 4

Write a Java program to demonstrate LocalDate functions

Output:

Explanation: In this example, the date1.isLeapYear() function is executed with the argument as 2017, since 2017 is not a leap year the output is printed as false. In date2, however, the function returns true since 2016 is a leap year.

Conclusion

  • The java.time.LocalDate class in Java is used for representing the current date and time depending on the location.
  • LocalDate is an immutable, thread-safe class that represents Date with the default format of yyyy-mm-dd.
  • The java.time.LocalDate class is declared as follows: