Java Reference ยท Date and Time
The LocalDate class
Reference for java.time.LocalDate: create dates, add and subtract days and months, compare, get fields, leap years, parse ISO text and convert to date-times.
java.time.LocalDate is a date without a time or a time zone: a year, a month and a day of the month, such as 2025-07-14. It is the right type for birthdays, due dates, invoice dates and anything else that is a day on the calendar rather than a moment in time.
A LocalDate is immutable. Methods such as plusDays and withMonth return a new object. The calendar is the ISO proleptic calendar: the Gregorian rules are applied to all years, including those before 1582. Years may range from -999999999 to +999999999.
LocalDate d = LocalDate.of(2025, 7, 14); LocalDate next = d.plusWeeks(2);
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.
Syntax
public final class LocalDate implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable
| Member | Description |
|---|---|
static LocalDate now() / now(ZoneId) / now(Clock) |
Today's date from the system clock, a zone or a given clock. |
static LocalDate of(int year, int month, int day) |
Creates a date; also accepts a Month enum. |
ofYearDay(int, int), ofEpochDay(long) |
By day of year or by days since 1970-01-01. |
static LocalDate parse(CharSequence) |
Parses yyyy-MM-dd; an overload takes a DateTimeFormatter. |
getYear(), getMonth(), getMonthValue(), getDayOfMonth(), getDayOfWeek(), getDayOfYear() |
Field accessors. |
plusDays/Weeks/Months/Years(long), minus... |
Date arithmetic; plus(Period) and plus(long, TemporalUnit) also exist. |
withDayOfMonth(int), withMonth(int), withYear(int), with(TemporalAdjuster) |
Replace one field or adjust. |
isBefore, isAfter, isEqual, compareTo, equals |
Comparison. |
until(ChronoLocalDate) / until(Temporal, TemporalUnit) |
Period or amount in one unit. |
datesUntil(LocalDate) (Java 9) |
Stream of dates, end exclusive. |
atTime(...), atStartOfDay(), atStartOfDay(ZoneId) |
Make a LocalDateTime or ZonedDateTime. |
isLeapYear(), lengthOfMonth(), lengthOfYear() |
Calendar facts. |
format(DateTimeFormatter) |
Text output. |
Throws: DateTimeException for an impossible date (such as February 30), DateTimeParseException for bad text.
Usage notes
- Month-end clamping.
plusMonthsandplusYearskeep the day of month if possible; otherwise they use the last valid day. Adding one month and then subtracting one month does not always return the original date. - Weeks start on Monday in
DayOfWeek, but week-based fields depend on the locale (seeDateTimeFormatter). isEqualvsequals: forLocalDatethey agree.compareToreturns the difference in years, then months, then days, not necessarily -1/0/1.now()is not testable. Pass aClockin code you want to test.- Today depends on the zone.
LocalDate.now()uses the JVM default zone; servers often run in UTC, so saynow(ZoneId.of("..."))explicitly. - Leap days:
LocalDate.of(2025, 2, 29)throws; February 29, 2024 exists. - Use
Period, notDuration, for date differences: seePeriod. - Ranges with
datesUntilexclude the end date.
Related
LocalTime,LocalDateTime,Period,ChronoUnit,TemporalAdjusters- Tutorial: Dates and Times