Top Description Fields Constructors Methods
java.time

public final Class LocalDate

extends Object
implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.time.chrono.ChronoLocalDate, java.lang.Comparable, java.time.temporal.TemporalAdjuster, java.time.temporal.Temporal, java.time.temporal.TemporalAccessor
Annotations
@ValueBased
Static Imports
java.time.LocalTime.SECONDS_PER_DAY, java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, .ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR, .ChronoField.ALIGNED_WEEK_OF_MONTH, .ChronoField.ALIGNED_WEEK_OF_YEAR, .ChronoField.DAY_OF_MONTH, .ChronoField.DAY_OF_YEAR, .ChronoField.EPOCH_DAY, .ChronoField.ERA, .ChronoField.MONTH_OF_YEAR, .ChronoField.PROLEPTIC_MONTH, .ChronoField.YEAR

A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03.

LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. For example, the value "2nd October 2007" can be stored in a LocalDate.

This class does not store or represent a time or time-zone. Instead, it is a description of the date, as used for birthdays. It cannot represent an instant on the time-line without additional information such as an offset or time-zone.

The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.

This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. The equals method should be used for comparisons.

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Field Summary

Modifier and TypeField and Description
private final short
day

The day-of-month.

pack-priv static final long
DAYS_0000_TO_1970

The number of days from year zero to year 1970.

private static final int
DAYS_PER_CYCLE

The number of days in a 400 year cycle.

public static final LocalDate
EPOCH

The epoch year LocalDate, '1970-01-01'.

public static final LocalDate
MAX

The maximum supported LocalDate, '+999999999-12-31'.

public static final LocalDate
MIN

The minimum supported LocalDate, '-999999999-01-01'.

private final short
month

The month-of-year.

private static final long
serialVersionUID

Serialization version.

private final int
year

The year.

Constructor Summary

AccessConstructor and Description
private
LocalDate(int
the year to represent, from MIN_YEAR to MAX_YEAR
year
,
int
the month-of-year to represent, not null
month
,
int
the day-of-month to represent, valid for year-month, from 1 to 31
dayOfMonth
)

Constructor, previously validated.

Method Summary

Modifier and TypeMethod and Description
public Temporal

Returns:

the adjusted object, not null
adjustInto
(Temporal
the target object to be adjusted, not null
temporal
)

Overrides default java.time.chrono.ChronoLocalDate.adjustInto.

Implements java.time.temporal.TemporalAdjuster.adjustInto.

Adjusts the specified temporal object to have the same date as this object.

public LocalDateTime

Returns:

the local date-time of midnight at the start of this date, not null
atStartOfDay
()

Combines this date with the time of midnight to create a LocalDateTime at the start of this date.

public ZonedDateTime

Returns:

the zoned date-time formed from this date and the earliest valid time for the zone, not null
atStartOfDay
(ZoneId
the zone ID to use, not null
zone
)

Returns a zoned date-time from this date at the earliest valid time according to the rules in the time-zone.

public LocalDateTime

Returns:

the local date-time formed from this date and the specified time, not null
atTime
(LocalTime
the time to combine with, not null
time
)

Overrides default java.time.chrono.ChronoLocalDate.atTime.

Combines this date with a time to create a LocalDateTime.

public LocalDateTime

Returns:

the local date-time formed from this date and the specified time, not null
atTime
(int
the hour-of-day to use, from 0 to 23
hour
,
int
the minute-of-hour to use, from 0 to 59
minute
)

Combines this date with a time to create a LocalDateTime.

public LocalDateTime

Returns:

the local date-time formed from this date and the specified time, not null
atTime
(int
the hour-of-day to use, from 0 to 23
hour
,
int
the minute-of-hour to use, from 0 to 59
minute
,
int
the second-of-minute to represent, from 0 to 59
second
)

Combines this date with a time to create a LocalDateTime.

public LocalDateTime

Returns:

the local date-time formed from this date and the specified time, not null
atTime
(int
the hour-of-day to use, from 0 to 23
hour
,
int
the minute-of-hour to use, from 0 to 59
minute
,
int
the second-of-minute to represent, from 0 to 59
second
,
int
the nano-of-second to represent, from 0 to 999,999,999
nanoOfSecond
)

Combines this date with a time to create a LocalDateTime.

public OffsetDateTime

Returns:

the offset date-time formed from this date and the specified time, not null
atTime
(OffsetTime
the time to combine with, not null
time
)

Combines this date with an offset time to create an OffsetDateTime.

public int

Returns:

the comparator value, that is the comparison of this local date with the other local date and this chronology with the other chronology, in order, returning the first non-zero result, and otherwise returning zero
compareTo
(ChronoLocalDate
the other date to compare to, not null
other
)

Overrides default java.time.chrono.ChronoLocalDate.compareTo.

Compares this date to another date.

pack-priv int
compareTo0(LocalDate otherDate)

private static LocalDate

Returns:

the local date, not null
create
(int
the year to represent, validated from MIN_YEAR to MAX_YEAR
year
,
int
the month-of-year to represent, from 1 to 12, validated
month
,
int
the day-of-month to represent, validated from 1 to 31
dayOfMonth
)

Creates a local date from the year, month and day fields.

public Stream<LocalDate>

Returns:

a sequential Stream for the range of LocalDate values
datesUntil
(LocalDate
the end date, exclusive, not null
endExclusive
)

Returns a sequential ordered stream of dates.

public Stream<LocalDate>

Returns:

a sequential Stream for the range of LocalDate values
datesUntil
(LocalDate
the end date, exclusive, not null
endExclusive
,
Period
the non-zero, non-negative Period which represents the step.
step
)

Returns a sequential ordered stream of dates by given incremental step.

pack-priv long
public boolean

Returns:

true if this is equal to the other date
equals
(Object
the object to check, null returns false
obj
)

Overrides java.lang.Object.equals.

Implements java.time.chrono.ChronoLocalDate.equals.

Checks if this date is equal to another date.

public String

Returns:

the formatted date string, not null
format
(DateTimeFormatter
the formatter to use, not null
formatter
)

Overrides default java.time.chrono.ChronoLocalDate.format.

Formats this date using the specified formatter.

public static LocalDate

Returns:

the local date, not null
from
(TemporalAccessor
the temporal object to convert, not null
temporal
)

Hides java.time.chrono.ChronoLocalDate.from.

Obtains an instance of LocalDate from a temporal object.

public int

Returns:

the value for the field
get
(TemporalField
the field to get, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.get.

Gets the value of the specified field from this date as an int.

private int
public IsoChronology

Returns:

the ISO chronology, not null
getChronology
()

Implements java.time.chrono.ChronoLocalDate.getChronology.

Gets the chronology of this date, which is the ISO calendar system.

public int

Returns:

the day-of-month, from 1 to 31
getDayOfMonth
()

Gets the day-of-month field.

public DayOfWeek

Returns:

the day-of-week, not null
getDayOfWeek
()

Gets the day-of-week field, which is an enum DayOfWeek.

public int

Returns:

the day-of-year, from 1 to 365, or 366 in a leap year
getDayOfYear
()

Gets the day-of-year field.

public IsoEra

Returns:

the IsoEra applicable at this date, not null
getEra
()

Overrides default java.time.chrono.ChronoLocalDate.getEra.

Gets the era applicable at this date.

public long

Returns:

the value for the field
getLong
(TemporalField
the field to get, not null
field
)

Implements java.time.temporal.TemporalAccessor.getLong.

Gets the value of the specified field from this date as a long.

public Month

Returns:

the month-of-year, not null
getMonth
()

Gets the month-of-year field using the Month enum.

public int

Returns:

the month-of-year, from 1 to 12
getMonthValue
()

Gets the month-of-year field from 1 to 12.

private long
public int

Returns:

the year, from MIN_YEAR to MAX_YEAR
getYear
()

Gets the year field.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.ChronoLocalDate.hashCode.

A hash code for this date.

public boolean

Returns:

true if this date is after the specified date
isAfter
(ChronoLocalDate
the other date to compare to, not null
other
)

Overrides default java.time.chrono.ChronoLocalDate.isAfter.

Checks if this date is after the specified date.

public boolean

Returns:

true if this date is before the specified date
isBefore
(ChronoLocalDate
the other date to compare to, not null
other
)

Overrides default java.time.chrono.ChronoLocalDate.isBefore.

Checks if this date is before the specified date.

public boolean

Returns:

true if this date is equal to the specified date
isEqual
(ChronoLocalDate
the other date to compare to, not null
other
)

Overrides default java.time.chrono.ChronoLocalDate.isEqual.

Checks if this date is equal to the specified date.

public boolean

Returns:

true if the year is leap, false otherwise
isLeapYear
()

Overrides default java.time.chrono.ChronoLocalDate.isLeapYear.

Checks if the year is a leap year, according to the ISO proleptic calendar system rules.

public boolean

Returns:

true if the field is supported on this date, false if not
isSupported
(TemporalField
the field to check, null returns false
field
)

Overrides default java.time.chrono.ChronoLocalDate.isSupported.

Implements java.time.temporal.TemporalAccessor.isSupported.

Checks if the specified field is supported.

public boolean

Returns:

true if the unit can be added/subtracted, false if not
isSupported
(TemporalUnit
the unit to check, null returns false
unit
)

Overrides default java.time.chrono.ChronoLocalDate.isSupported.

Implements java.time.temporal.Temporal.isSupported.

Checks if the specified unit is supported.

public int

Returns:

the length of the month in days
lengthOfMonth
()

Implements java.time.chrono.ChronoLocalDate.lengthOfMonth.

Returns the length of the month represented by this date.

public int

Returns:

366 if the year is leap, 365 otherwise
lengthOfYear
()

Overrides default java.time.chrono.ChronoLocalDate.lengthOfYear.

Returns the length of the year represented by this date.

public LocalDate

Returns:

a LocalDate based on this date with the subtraction made, not null
minus
(TemporalAmount
the amount to subtract, not null
amountToSubtract
)

Overrides default java.time.temporal.Temporal.minus, java.time.chrono.ChronoLocalDate.minus.

Returns a copy of this date with the specified amount subtracted.

public LocalDate

Returns:

a LocalDate based on this date with the specified amount subtracted, not null
minus
(long
the amount of the unit to subtract from the result, may be negative
amountToSubtract
,
TemporalUnit
the unit of the amount to subtract, not null
unit
)

Overrides default java.time.temporal.Temporal.minus, java.time.chrono.ChronoLocalDate.minus.

Returns a copy of this date with the specified amount subtracted.

public LocalDate

Returns:

a LocalDate based on this date with the days subtracted, not null
minusDays
(long
the days to subtract, may be negative
daysToSubtract
)

Returns a copy of this LocalDate with the specified number of days subtracted.

public LocalDate

Returns:

a LocalDate based on this date with the months subtracted, not null
minusMonths
(long
the months to subtract, may be negative
monthsToSubtract
)

Returns a copy of this LocalDate with the specified number of months subtracted.

public LocalDate

Returns:

a LocalDate based on this date with the weeks subtracted, not null
minusWeeks
(long
the weeks to subtract, may be negative
weeksToSubtract
)

Returns a copy of this LocalDate with the specified number of weeks subtracted.

public LocalDate

Returns:

a LocalDate based on this date with the years subtracted, not null
minusYears
(long
the years to subtract, may be negative
yearsToSubtract
)

Returns a copy of this LocalDate with the specified number of years subtracted.

private long
public static LocalDate

Returns:

the current date using the system clock and default time-zone, not null
now
()

Obtains the current date from the system clock in the default time-zone.

public static LocalDate

Returns:

the current date using the system clock, not null
now
(ZoneId
the zone ID to use, not null
zone
)

Obtains the current date from the system clock in the specified time-zone.

public static LocalDate

Returns:

the current date, not null
now
(Clock
the clock to use, not null
clock
)

Obtains the current date from the specified clock.

public static LocalDate

Returns:

the local date, not null
of
(int
the year to represent, from MIN_YEAR to MAX_YEAR
year
,
Month
the month-of-year to represent, not null
month
,
int
the day-of-month to represent, from 1 to 31
dayOfMonth
)

Obtains an instance of LocalDate from a year, month and day.

public static LocalDate

Returns:

the local date, not null
of
(int
the year to represent, from MIN_YEAR to MAX_YEAR
year
,
int
the month-of-year to represent, from 1 (January) to 12 (December)
month
,
int
the day-of-month to represent, from 1 to 31
dayOfMonth
)

Obtains an instance of LocalDate from a year, month and day.

public static LocalDate

Returns:

the local date, not null
ofEpochDay
(long
the Epoch Day to convert, based on the epoch 1970-01-01
epochDay
)

Obtains an instance of LocalDate from the epoch day count.

public static LocalDate

Returns:

the local date, not null
ofInstant
(Instant
the instant to create the date from, not null
instant
,
ZoneId
the time-zone, which may be an offset, not null
zone
)

Obtains an instance of LocalDate from an Instant and zone ID.

This creates a local date based on the specified instant.

public static LocalDate

Returns:

the local date, not null
ofYearDay
(int
the year to represent, from MIN_YEAR to MAX_YEAR
year
,
int
the day-of-year to represent, from 1 to 366
dayOfYear
)

Obtains an instance of LocalDate from a year and day-of-year.

public static LocalDate

Returns:

the parsed local date, not null
parse
(CharSequence
the text to parse such as "2007-12-03", not null
text
)

Obtains an instance of LocalDate from a text string such as 2007-12-03.

public static LocalDate

Returns:

the parsed local date, not null
parse
(CharSequence
the text to parse, not null
text
,
DateTimeFormatter
the formatter to use, not null
formatter
)

Obtains an instance of LocalDate from a text string using a specific formatter.

public LocalDate

Returns:

a LocalDate based on this date with the addition made, not null
plus
(TemporalAmount
the amount to add, not null
amountToAdd
)

Overrides default java.time.temporal.Temporal.plus, java.time.chrono.ChronoLocalDate.plus.

Returns a copy of this date with the specified amount added.

public LocalDate

Returns:

a LocalDate based on this date with the specified amount added, not null
plus
(long
the amount of the unit to add to the result, may be negative
amountToAdd
,
TemporalUnit
the unit of the amount to add, not null
unit
)

Overrides default java.time.chrono.ChronoLocalDate.plus.

Implements java.time.temporal.Temporal.plus.

Returns a copy of this date with the specified amount added.

public LocalDate

Returns:

a LocalDate based on this date with the days added, not null
plusDays
(long
the days to add, may be negative
daysToAdd
)

Returns a copy of this LocalDate with the specified number of days added.

public LocalDate

Returns:

a LocalDate based on this date with the months added, not null
plusMonths
(long
the months to add, may be negative
monthsToAdd
)

Returns a copy of this LocalDate with the specified number of months added.

public LocalDate

Returns:

a LocalDate based on this date with the weeks added, not null
plusWeeks
(long
the weeks to add, may be negative
weeksToAdd
)

Returns a copy of this LocalDate with the specified number of weeks added.

public LocalDate

Returns:

a LocalDate based on this date with the years added, not null
plusYears
(long
the years to add, may be negative
yearsToAdd
)

Returns a copy of this LocalDate with the specified number of years added.

public <
the type of the result
R
>
R

Returns:

the query result, null may be returned (defined by the query)
query
(TemporalQuery<R>
the query to invoke, not null
query
)

Overrides default java.time.temporal.TemporalAccessor.query, java.time.chrono.ChronoLocalDate.query.

Queries this date using the specified query.

public ValueRange

Returns:

the range of valid values for the field, not null
range
(TemporalField
the field to query the range for, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.range.

Gets the range of valid values for the specified field.

pack-priv static LocalDate
private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

private static LocalDate

Returns:

the resolved date, not null
resolvePreviousValid
(int
the year to represent, validated from MIN_YEAR to MAX_YEAR
year
,
int
the month-of-year to represent, validated from 1 to 12
month
,
int
the day-of-month to represent, validated from 1 to 31
day
)

Resolves the date, resolving days past the end of month.

public long
toEpochDay()

Overrides default java.time.chrono.ChronoLocalDate.toEpochDay.

Converts this date to the Epoch Day.

public long

Returns:

the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative
toEpochSecond
(LocalTime
the local time, not null
time
,
ZoneOffset
the zone offset, not null
offset
)

Converts this LocalDate to the number of seconds since the epoch of 1970-01-01T00:00:00Z.

public String

Returns:

a string representation of this date, not null
toString
()

Overrides java.lang.Object.toString.

Implements java.time.chrono.ChronoLocalDate.toString.

Outputs this date as a String, such as 2007-12-03.

public long

Returns:

the amount of time between this date and the end date
until
(Temporal
the end date, exclusive, which is converted to a LocalDate, not null
endExclusive
,
TemporalUnit
the unit to measure the amount in, not null
unit
)

Implements java.time.temporal.Temporal.until, java.time.chrono.ChronoLocalDate.until.

Calculates the amount of time until another date in terms of the specified unit.

public Period

Returns:

the period between this date and the end date, not null
until
(ChronoLocalDate
the end date, exclusive, which may be in any chronology, not null
endDateExclusive
)

Implements java.time.chrono.ChronoLocalDate.until.

Calculates the period between this date and another date as a Period.

public LocalDate

Returns:

a LocalDate based on this with the adjustment made, not null
with
(TemporalAdjuster
the adjuster to use, not null
adjuster
)

Overrides default java.time.temporal.Temporal.with, java.time.chrono.ChronoLocalDate.with.

Returns an adjusted copy of this date.

public LocalDate

Returns:

a LocalDate based on this with the specified field set, not null
with
(TemporalField
the field to set in the result, not null
field
,
long
the new value of the field in the result
newValue
)

Overrides default java.time.chrono.ChronoLocalDate.with.

Implements java.time.temporal.Temporal.with.

Returns a copy of this date with the specified field set to a new value.

public LocalDate

Returns:

a LocalDate based on this date with the requested day, not null
withDayOfMonth
(int
the day-of-month to set in the result, from 1 to 28-31
dayOfMonth
)

Returns a copy of this LocalDate with the day-of-month altered.

public LocalDate

Returns:

a LocalDate based on this date with the requested day, not null
withDayOfYear
(int
the day-of-year to set in the result, from 1 to 365-366
dayOfYear
)

Returns a copy of this LocalDate with the day-of-year altered.

public LocalDate

Returns:

a LocalDate based on this date with the requested month, not null
withMonth
(int
the month-of-year to set in the result, from 1 (January) to 12 (December)
month
)

Returns a copy of this LocalDate with the month-of-year altered.

public LocalDate

Returns:

a LocalDate based on this date with the requested year, not null
withYear
(int
the year to set in the result, from MIN_YEAR to MAX_YEAR
year
)

Returns a copy of this LocalDate with the year altered.

pack-priv void
private Object

Returns:

the instance of Ser, not null
writeReplace
()

Writes the object using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait