public final class LocalDate extends Object implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable
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; use of identity-sensitive operations (including reference equality
(==
), identity hash code, or synchronization) on instances of
LocalDate
may have unpredictable results and should be avoided.
The equals
method should be used for comparisons.
Modifier and Type | Field | Description |
---|---|---|
static LocalDate |
MAX |
The maximum supported
LocalDate , '+999999999-12-31'. |
static LocalDate |
MIN |
The minimum supported
LocalDate , '-999999999-01-01'. |
Modifier and Type | Method | Description |
---|---|---|
Temporal |
adjustInto(Temporal temporal) |
Adjusts the specified temporal object to have the same date as this object.
|
LocalDateTime |
atStartOfDay() |
Combines this date with the time of midnight to create a
LocalDateTime
at the start of this date. |
ZonedDateTime |
atStartOfDay(ZoneId zone) |
Returns a zoned date-time from this date at the earliest valid time according
to the rules in the time-zone.
|
LocalDateTime |
atTime(int hour,
int minute) |
Combines this date with a time to create a
LocalDateTime . |
LocalDateTime |
atTime(int hour,
int minute,
int second) |
Combines this date with a time to create a
LocalDateTime . |
LocalDateTime |
atTime(int hour,
int minute,
int second,
int nanoOfSecond) |
Combines this date with a time to create a
LocalDateTime . |
LocalDateTime |
atTime(LocalTime time) |
Combines this date with a time to create a
LocalDateTime . |
OffsetDateTime |
atTime(OffsetTime time) |
Combines this date with an offset time to create an
OffsetDateTime . |
int |
compareTo(ChronoLocalDate other) |
Compares this date to another date.
|
boolean |
equals(Object obj) |
Checks if this date is equal to another date.
|
String |
format(DateTimeFormatter formatter) |
Formats this date using the specified formatter.
|
static LocalDate |
from(TemporalAccessor temporal) |
Obtains an instance of
LocalDate from a temporal object. |
int |
get(TemporalField field) |
Gets the value of the specified field from this date as an
int . |
IsoChronology |
getChronology() |
Gets the chronology of this date, which is the ISO calendar system.
|
int |
getDayOfMonth() |
Gets the day-of-month field.
|
DayOfWeek |
getDayOfWeek() |
Gets the day-of-week field, which is an enum
DayOfWeek . |
int |
getDayOfYear() |
Gets the day-of-year field.
|
Era |
getEra() |
Gets the era applicable at this date.
|
long |
getLong(TemporalField field) |
Gets the value of the specified field from this date as a
long . |
Month |
getMonth() |
Gets the month-of-year field using the
Month enum. |
int |
getMonthValue() |
Gets the month-of-year field from 1 to 12.
|
int |
getYear() |
Gets the year field.
|
int |
hashCode() |
A hash code for this date.
|
boolean |
isAfter(ChronoLocalDate other) |
Checks if this date is after the specified date.
|
boolean |
isBefore(ChronoLocalDate other) |
Checks if this date is before the specified date.
|
boolean |
isEqual(ChronoLocalDate other) |
Checks if this date is equal to the specified date.
|
boolean |
isLeapYear() |
Checks if the year is a leap year, according to the ISO proleptic
calendar system rules.
|
boolean |
isSupported(TemporalField field) |
Checks if the specified field is supported.
|
boolean |
isSupported(TemporalUnit unit) |
Checks if the specified unit is supported.
|
int |
lengthOfMonth() |
Returns the length of the month represented by this date.
|
int |
lengthOfYear() |
Returns the length of the year represented by this date.
|
LocalDate |
minus(long amountToSubtract,
TemporalUnit unit) |
Returns a copy of this date with the specified amount subtracted.
|
LocalDate |
minus(TemporalAmount amountToSubtract) |
Returns a copy of this date with the specified amount subtracted.
|
LocalDate |
minusDays(long daysToSubtract) |
Returns a copy of this
LocalDate with the specified number of days subtracted. |
LocalDate |
minusMonths(long monthsToSubtract) |
Returns a copy of this
LocalDate with the specified number of months subtracted. |
LocalDate |
minusWeeks(long weeksToSubtract) |
Returns a copy of this
LocalDate with the specified number of weeks subtracted. |
LocalDate |
minusYears(long yearsToSubtract) |
Returns a copy of this
LocalDate with the specified number of years subtracted. |
static LocalDate |
now() |
Obtains the current date from the system clock in the default time-zone.
|
static LocalDate |
now(Clock clock) |
Obtains the current date from the specified clock.
|
static LocalDate |
now(ZoneId zone) |
Obtains the current date from the system clock in the specified time-zone.
|
static LocalDate |
of(int year,
int month,
int dayOfMonth) |
Obtains an instance of
LocalDate from a year, month and day. |
static LocalDate |
of(int year,
Month month,
int dayOfMonth) |
Obtains an instance of
LocalDate from a year, month and day. |
static LocalDate |
ofEpochDay(long epochDay) |
Obtains an instance of
LocalDate from the epoch day count. |
static LocalDate |
ofYearDay(int year,
int dayOfYear) |
Obtains an instance of
LocalDate from a year and day-of-year. |
static |