public final class LocalDate extends Object implements DateTime, DateTime.WithAdjuster, Comparable<LocalDate>, Serializable
2007-12-03
.
LocalDate
is an immutable calendrical that represents a date, often viewed
as year-month-day. This object can also access other date fields such as
day-of-year, day-of-week and week-of-year.
This class does not store or represent a time or time-zone.
For example, the value "2nd October 2007" can be stored in a LocalDate
.
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 todays'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 rules unsuitable. In this case, the
application code should use HistoricDate
and define an explicit
cutover date between the Julian and Gregorian calendar systems.
DateTime.MinusAdjuster, DateTime.PlusAdjuster, DateTime.WithAdjuster
Modifier and Type | Field and Description |
---|---|
static LocalDate |
MAX_DATE
Constant for the maximum date on the proleptic ISO calendar system, +999999999-12-31.
|
static LocalDate |
MIN_DATE
Constant for the minimum date on the proleptic ISO calendar system, -999999999-01-01.
|
Modifier and Type | Method and Description |
---|---|
OffsetDate |
atOffset(ZoneOffset offset)
Returns an offset date formed from this time and the specified offset.
|
ZonedDateTime |
atStartOfDayInZone(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)
Returns a local date-time formed from this date at the specified time.
|
LocalDateTime |
atTime(int hour,
int minute,
int second)
Returns a local date-time formed from this date at the specified time.
|
LocalDateTime |
atTime(int hour,
int minute,
int second,
int nanoOfSecond)
Returns a local date-time formed from this date at the specified time.
|
LocalDateTime |
atTime(LocalTime localTime)
Returns a local date-time formed from this date at the specified time.
|
OffsetDateTime |
atTime(OffsetTime offsetTime)
Returns a local date-time formed from this date at the specified offset time.
|
int |
compareTo(LocalDate other)
Compares this
LocalDate to another date. |
DateTime |
doAdjustment(DateTime dateTime)
Implementation of the strategy to make an adjustment to the specified date-time object.
|
boolean |
equals(Object obj)
Checks if this date is equal to another date.
|
<R> R |
extract(Class<R> type)
Extracts date-time information in a generic way.
|
static LocalDate |
from(DateTimeAccessor calendrical)
Obtains an instance of
LocalDate from a calendrical. |
int |
get(DateTimeField field)
Gets the value of the specified date-time field as an
int . |
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.
|
long |
getLong(DateTimeField field)
Gets the value of the specified date-time field 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(LocalDate other)
Checks if this
LocalDate is after the specified date. |
boolean |
isBefore(LocalDate other)
Checks if this
LocalDate is before the specified date. |
boolean |
isLeapYear()
Checks if the year is a leap year, according to the ISO proleptic
calendar system rules.
|
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(DateTime.MinusAdjuster adjuster)
Returns a copy of this date with the specified period subtracted.
|
LocalDate |
minus(long amountToSubtract,
PeriodUnit unit)
Returns a copy of this date with the specified period 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 period in months subtracted. |
LocalDate |
minusWeeks(long weeksToSubtract)
Returns a copy of this
LocalDate with the specified period in weeks subtracted. |
LocalDate |
minusYears(long yearsToSubtract)
Returns a copy of this
LocalDate with the specified period in 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 LocalDate |
parse(CharSequence text)
Obtains an instance of
LocalDate from a text string such as 2007-12-03 . |
static LocalDate |
parse(CharSequence text,
CalendricalFormatter formatter)
Obtains an instance of
LocalDate from a text string using a specific formatter. |
long |
periodUntil(DateTime endDateTime,
PeriodUnit unit)
Calculates the period from this date-time until the given date-time in the specified unit.
|
LocalDate |
plus(DateTime.PlusAdjuster adjuster)
Returns a copy of this date with the specified period added.
|
LocalDate |
plus(long amountToAdd,
PeriodUnit unit)
Returns a copy of this date with the specified period added.
|
LocalDate |
plusDays(long daysToAdd)
Returns a copy of this
LocalDate with the specified number of days added. |
LocalDate |
plusMonths(long monthsToAdd)
Returns a copy of this
LocalDate with the specified period in months added. |
LocalDate |
plusWeeks(long weeksToAdd)
Returns a copy of this
LocalDate with the specified period in weeks added. |
LocalDate |
plusYears(long yearsToAdd)
Returns a copy of this
LocalDate with the specified period in years added. |
DateTimeValueRange |
range(DateTimeField field)
Gets the range of valid values for the specified date-time field.
|
long |
toEpochDay()
Converts this
LocalDate to Epoch Days. |
String |
toString()
Outputs this date as a
String , such as 2007-12-03 . |
String |
toString(CalendricalFormatter formatter)
Outputs this date as a
String using the formatter. |
LocalDate |
with(DateTime.WithAdjuster adjuster)
Returns an adjusted date based on this date.
|
LocalDate |
with(DateTimeField field,
long newValue)
Returns a copy of this date with the specified field altered.
|
LocalDate |
withDayOfMonth(int dayOfMonth)
Returns a copy of this
LocalDate with the day-of-month altered. |
LocalDate |
withDayOfYear(int dayOfYear)
Returns a copy of this
LocalDate with the day-of-year altered. |
LocalDate |
withMonth(int month)
Returns a copy of this
LocalDate with the month-of-year altered. |
LocalDate |
withYear(int year)
Returns a copy of this
LocalDate with the year altered. |
public static final LocalDate MIN_DATE
public static final LocalDate MAX_DATE
public static LocalDate now()
This will query the system clock
in the default
time-zone to obtain the current date.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
public static LocalDate now(ZoneId zone)
This will query the system clock
to obtain the current date.
Specifying the time-zone avoids dependence on the default time-zone.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
public static LocalDate now(Clock clock)
This will query the specified clock to obtain the current date - today.
Using this method allows the use of an alternate clock for testing.
The alternate clock may be introduced using dependency injection
.
clock
- the clock to use, not nullpublic static LocalDate of(int year, Month month, int dayOfMonth)
LocalDate
from a year, month and day.
The day must be valid for the year and month, otherwise an exception will be thrown.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonth
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31DateTimeException
- if the value of any field is out of rangeDateTimeException
- if the day-of-month is invalid for the month-yearpublic static LocalDate of(int year, int month, int dayOfMonth)
LocalDate
from a year, month and day.
The day must be valid for the year and month, otherwise an exception will be thrown.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonth
- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth
- the day-of-month to represent, from 1 to 31DateTimeException
- if the value of any field is out of rangeDateTimeException
- if the day-of-month is invalid for the month-yearpublic static LocalDate ofYearDay(int year, int dayOfYear)
LocalDate
from a year and day-of-year.
The day-of-year must be valid for the year, otherwise an exception will be thrown.
year
- the year to represent, from MIN_YEAR to MAX_YEARdayOfYear
- the day-of-year to represent, from 1 to 366DateTimeException
- if the value of any field is out of rangeDateTimeException
- if the day-of-year is invalid for the month-yearpublic static LocalDate ofEpochDay(long epochDay)
LocalDate
from the epoch day count.
The Epoch Day count is a simple incrementing count of days where day 0 is 1970-01-01. Negative numbers represent earlier days.
epochDay
- the Epoch Day to convert, based on the epoch 1970-01-01DateTimeException
- if the epoch days exceeds the supported date rangepublic static LocalDate from(DateTimeAccessor calendrical)
LocalDate
from a calendrical.
A calendrical represents some form of date and time information.
This factory converts the arbitrary calendrical to an instance of LocalDate
.
calendrical
- the calendrical to convert, not nullDateTimeException
- if unable to convert to a LocalDate
public static LocalDate parse(CharSequence text)
LocalDate
from a text string such as 2007-12-03
.
The string must represent a valid date and is parsed using
DateTimeFormatters.isoLocalDate()
.
text
- the text to parse such as "2007-12-03", not nullDateTimeParseException
- if the text cannot be parsedpublic static LocalDate parse(CharSequence text, CalendricalFormatter formatter)
LocalDate
from a text string using a specific formatter.
The text is parsed using the formatter, returning a date.
text
- the text to parse, not nullformatter
- the formatter to use, not nullDateTimeParseException
- if the text cannot be parsedpublic DateTimeValueRange range(DateTimeField field)
DateTimeAccessor
All fields can be expressed as a long
integer.
This method returns an object that describes the valid range for that value.
Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.
This method will return a result whether or not the implementation supports the field.
LocalDateTimeField
before
delegating on to the doRange method
on the specified field.range
in interface DateTimeAccessor
field
- the field to get, not nullpublic int get(DateTimeField field)
DateTimeAccessor
int
.
This queries the date-time for the value for the specified field. The returned value will always be within the valid range of values for the field. If the date-time cannot return the value an exception will be thrown.
LocalDateTimeField
before
delegating on to the doGet method
on the specified field.get
in interface DateTimeAccessor
field
- the field to get, not nullpublic long getLong(DateTimeField field)
DateTimeAccessor
Long
.
This queries the date-time for the value for the specified field. The returned value may be outside the valid range of values for the field. If the date-time cannot return the value, it will throw an exception.
LocalDateTimeField
before
delegating on to the doGet method
on the specified field.getLong
in interface DateTimeAccessor
field
- the field to get, not nullpublic int getYear()
This method returns the primitive int
value for the year.
public int getMonthValue()
This method returns the month as an int
from 1 to 12.
Application code is frequently clearer if the enum Month
is used by calling getMonth()
.
getMonth()
public Month getMonth()
Month
enum.
This method returns the enum Month
for the month.
This avoids confusion as to what int
values mean.
If you need access to the primitive int
value then the enum
provides the int value
.
getMonthValue()
public int getDayOfMonth()
This method returns the primitive int
value for the day-of-month.
public int getDayOfYear()
This method returns the primitive int
value for the day-of-year.
public DayOfWeek getDayOfWeek()
DayOfWeek
.
This method returns the enum DayOfWeek
for the day-of-week.
This avoids confusion as to what int
values mean.
If you need access to the primitive int
value then the enum
provides the int value
.
Additional information can be obtained from the DayOfWeek
.
This includes textual names of the values.
public boolean isLeapYear()
This method applies the current rules for leap years across the whole time-line. In general, a year is a leap year if it is divisible by four without remainder. However, years divisible by 100, are not leap years, with the exception of years divisible by 400 which are.
For example, 1904 is a leap year it is divisible by 4. 1900 was not a leap year as it is divisible by 100, however 2000 was a leap year as it is divisible by 400.
The calculation is proleptic - applying the same rules into the far future and far past. This is historically inaccurate, but is correct for the ISO-8601 standard.
public int lengthOfMonth()
This returns the length of the month in days. For example, a date in January would return 31.
public int lengthOfYear()
This returns the length of the year in days, either 365 or 366.
public LocalDate with(DateTime.WithAdjuster adjuster)
This adjusts the date according to the rules of the specified adjuster.
A simple adjuster might simply set the one of the fields, such as the year field.
A more complex adjuster might set the date to the last day of the month.
A selection of common adjustments is provided in DateTimeAdjusters
.
These include finding the "last day of the month" and "next Wednesday".
The adjuster is responsible for handling special cases, such as the varying
lengths of month and leap years.
In addition, all principal classes implement the DateTime.WithAdjuster
interface,
including this one. For example, Month
implements the adjuster interface.
As such, this code will compile and run:
date.with(Month.JULY);
This instance is immutable and unaffected by this method call.
with
in interface DateTime
adjuster
- the adjuster to use, not nullLocalDate
based on this date with the adjustment made, not nullDateTimeException
- if the adjustment cannot be madepublic LocalDate with(DateTimeField field, long newValue)
This method returns a new date based on this date with a new value for the specified field. This can be used to change any field, for example to set the year, month of day-of-month.
In some cases, changing the specified field can cause the resulting date to become invalid, such as changing the month from January to February would make the day-of-month 31 invalid. In cases like this, the field is responsible for resolving the date. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
This instance is immutable and unaffected by this method call.
with
in interface DateTime
with
in interface DateTimeAccessor
field
- the field to set in the returned date, not nullnewValue
- the new value of the field in the returned date, not nullLocalDate
based on this date with the specified field set, not nullDateTimeException
- if the value is invalidpublic LocalDate withYear(int year)
LocalDate
with the year altered.
If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
This instance is immutable and unaffected by this method call.
year
- the year to set in the returned date, from MIN_YEAR to MAX_YEARLocalDate
based on this date with the requested year, not nullDateTimeException
- if the year value is invalidpublic LocalDate withMonth(int month)
LocalDate
with the month-of-year altered.
If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
This instance is immutable and unaffected by this method call.
month
- the month-of-year to set in the returned date, from 1 (January) to 12 (December)LocalDate
based on this date with the requested month, not nullDateTimeException
- if the month-of-year value is invalidpublic LocalDate withDayOfMonth(int dayOfMonth)
LocalDate
with the day-of-month altered.
If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
dayOfMonth
- the day-of-month to set in the returned date, from 1 to 28-31LocalDate
based on this date with the requested day, not nullDateTimeException
- if the day-of-month value is invalidDateTimeException
- if the day-of-month is invalid for the month-yearpublic LocalDate withDayOfYear(int dayOfYear)
LocalDate
with the day-of-year altered.
If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
dayOfYear
- the day-of-year to set in the returned date, from 1 to 365-366LocalDate
based on this date with the requested day, not nullDateTimeException
- if the day-of-year value is invalidDateTimeException
- if the day-of-year is invalid for the yearpublic LocalDate plus(DateTime.PlusAdjuster adjuster)
This method returns a new date based on this date with the specified period added.
The adjuster is typically Period
but may be any other type implementing
the DateTime.PlusAdjuster
interface.
The calculation is delegated to the specified adjuster, which typically calls
back to plus(long, PeriodUnit)
.
This instance is immutable and unaffected by this method call.
plus
in interface DateTime
adjuster
- the adjuster to use, not nullLocalDate
based on this date with the addition made, not nullDateTimeException
- if the addition cannot be madeArithmeticException
- if numeric overflow occurspublic LocalDate plus(long amountToAdd, PeriodUnit unit)
This method returns a new date based on this date with the specified period added. This can be used to add any period that is defined by a unit, for example to add years, months or days. The unit is responsible for the details of the calculation, including the resolution of any edge cases in the calculation.
This instance is immutable and unaffected by this method call.
plus
in interface DateTime
amountToAdd
- the amount of the unit to add to the returned date, not nullunit
- the unit of the period to add, not nullLocalDate
based on this date with the specified period added, not nullDateTimeException
- if the unit cannot be added to this typepublic LocalDate plusYears(long yearsToAdd)
LocalDate
with the specified period in years added.
This method adds the specified amount to the years field in three steps:
For example, 2008-02-29 (leap year) plus one year would result in the invalid date 2009-02-29 (standard year). Instead of returning an invalid result, the last valid day of the month, 2009-02-28, is selected instead.
This instance is immutable and unaffected by this method call.
yearsToAdd
- the years to add, may be negativeLocalDate
based on this date with the years added, not nullDateTimeException
- if the result exceeds the supported date rangepublic LocalDate plusMonths(long monthsToAdd)
LocalDate
with the specified period in months added.
This method adds the specified amount to the months field in three steps:
For example, 2007-03-31 plus one month would result in the invalid date 2007-04-31. Instead of returning an invalid result, the last valid day of the month, 2007-04-30, is selected instead.
This instance is immutable and unaffected by this method call.
monthsToAdd
- the months to add, may be negativeLocalDate
based on this date with the months added, not nullDateTimeException
- if the result exceeds the supported date rangepublic LocalDate plusWeeks(long weeksToAdd)
LocalDate
with the specified period in weeks added.
This method adds the specified amount in weeks to the days field incrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.
For example, 2008-12-31 plus one week would result in 2009-01-07.
This instance is immutable and unaffected by this method call.
weeksToAdd
- the weeks to add, may be negativeLocalDate
based on this date with the weeks added, not nullDateTimeException
- if the result exceeds the supported date rangepublic LocalDate plusDays(long daysToAdd)
LocalDate
with the specified number of days added.
This method adds the specified amount to the days field incrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.
For example, 2008-12-31 plus one day would result in 2009-01-01.
This instance is immutable and unaffected by this method call.
daysToAdd
- the days to add, may be negativeLocalDate
based on this date with the days added, not nullDateTimeException
- if the result exceeds the supported date rangepublic LocalDate minus(DateTime.MinusAdjuster adjuster)
This method returns a new date based on this date with the specified period subtracted.
The adjuster is typically Period
but may be any other type implementing
the DateTime.MinusAdjuster
interface.
The calculation is delegated to the specified adjuster, which typically calls
back to minus(long, PeriodUnit)
.
This instance is immutable and unaffected by this method call.
minus
in interface DateTime
adjuster
- the adjuster to use, not nullLocalDate
based on this date with the subtraction made, not nullDateTimeException
- if the subtraction cannot be madeArithmeticException
- if numeric overflow occurspublic LocalDate minus(long amountToSubtract, PeriodUnit unit)
This method returns a new date based on this date with the specified period subtracted. This can be used to subtract any period that is defined by a unit, for example to subtract years, months or days. The unit is responsible for the details of the calculation, including the resolution of any edge cases in the calculation.
This instance is immutable and unaffected by this method call.
minus
in interface DateTime
amountToSubtract
- the amount of the unit to subtract from the returned date, not nullunit
- the unit of the period to subtract, not nullLocalDate
based on this date with the specified period subtracted, not nullDateTimeException
- if the unit cannot be added to this typepublic LocalDate minusYears(long yearsToSubtract)
LocalDate
with the specified period in years subtracted.
This method subtracts the specified amount from the years field in three steps:
For example, 2008-02-29 (leap year) minus one year would result in the invalid date 2007-02-29 (standard year). Instead of returning an invalid result, the last valid day of the month, 2007-02-28, is selected instead.
This instance is immutable and unaffected by this method call.
yearsToSubtract
- the years to subtract, may be negativeLocalDate
based on this date with the years subtracted, not nullDateTimeException
- if the result exceeds the supported date rangepublic LocalDate minusMonths(long monthsToSubtract)
LocalDate
with the specified period in months subtracted.
This method subtracts the specified amount from the months field in three steps:
For example, 2007-03-31 minus one month would result in the invalid date 2007-02-31. Instead of returning an invalid result, the last valid day of the month, 2007-02-28, is selected instead.
This instance is immutable and unaffected by this method call.
monthsToSubtract
- the months to subtract, may be negativeLocalDate
based on this date with the months subtracted, not nullDateTimeException
- if the result exceeds the supported date rangepublic LocalDate minusWeeks(long weeksToSubtract)
LocalDate
with the specified period in weeks subtracted.
This method subtracts the specified amount in weeks from the days field decrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.
For example, 2009-01-07 minus one week would result in 2008-12-31.
This instance is immutable and unaffected by this method call.
weeksToSubtract
- the weeks to subtract, may be negativeLocalDate
based on this date with the weeks subtracted, not nullDateTimeException
- if the result exceeds the supported date rangepublic LocalDate minusDays(long daysToSubtract)
LocalDate
with the specified number of days subtracted.
This method subtracts the specified amount from the days field decrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.
For example, 2009-01-01 minus one day would result in 2008-12-31.
This instance is immutable and unaffected by this method call.
daysToSubtract
- the days to subtract, may be negativeLocalDate
based on this date with the days subtracted, not nullDateTimeException
- if the result exceeds the supported date rangepublic OffsetDateTime atTime(OffsetTime offsetTime)
This merges the two objects - this
and the specified time -
to form an instance of OffsetDateTime
.
This instance is immutable and unaffected by this method call.
offsetTime
- the offset time to use, not nullpublic LocalDateTime atTime(LocalTime localTime)
This merges the two objects - this
and the specified time -
to form an instance of LocalDateTime
.
This instance is immutable and unaffected by this method call.
localTime
- the local time to use, not nullpublic LocalDateTime atTime(int hour, int minute)
This merges the three values - this
and the specified time -
to form an instance of LocalDateTime
.
This instance is immutable and unaffected by this method call.
hour
- the hour-of-day to use, from 0 to 23minute
- the minute-of-hour to use, from 0 to 59DateTimeException
- if the value of any field is out of rangepublic LocalDateTime atTime(int hour, int minute, int second)
This merges the four values - this
and the specified time -
to form an instance of LocalDateTime
.
This instance is immutable and unaffected by this method call.
hour
- the hour-of-day to use, from 0 to 23minute
- the minute-of-hour to use, from 0 to 59second
- the second-of-minute to represent, from 0 to 59DateTimeException
- if the value of any field is out of rangepublic LocalDateTime atTime(int hour, int minute, int second, int nanoOfSecond)
This merges the five values - this
and the specified time -
to form an instance of LocalDateTime
.
This instance is immutable and unaffected by this method call.
hour
- the hour-of-day to use, from 0 to 23minute
- the minute-of-hour to use, from 0 to 59second
- the second-of-minute to represent, from 0 to 59nanoOfSecond
- the nano-of-second to represent, from 0 to 999,999,999DateTimeException
- if the value of any field is out of rangepublic OffsetDate atOffset(ZoneOffset offset)
This merges the two objects - this
and the specified offset -
to form an instance of OffsetDate
.
This instance is immutable and unaffected by this method call.
offset
- the offset to use, not nullpublic ZonedDateTime atStartOfDayInZone(ZoneId zone)
Time-zone rules, such as daylight savings, mean that not every time on the
local time-line exists. If the local date is in a gap or overlap according to
the rules then a resolver is used to determine the resultant local time and offset.
This method uses the post-gap pre-overlap
resolver.
This selects the date-time immediately after a gap and the earlier offset in overlaps.
This combination chooses the earliest valid local time on the date, typically midnight.
To convert to a specific time in a given time-zone call atTime(LocalTime)
followed by LocalDateTime.atZone(ZoneId)
.
This instance is immutable and unaffected by this method call.
zone
- the time-zone to use, not nullpublic <R> R extract(Class<R> type)
This method exists to fulfill the DateTimeAccessor
interface.
This implementation returns the following types:
extract
in interface DateTimeAccessor
R
- the type to extracttype
- the type to extract, null returns nullpublic DateTime doAdjustment(DateTime dateTime)
DateTime.WithAdjuster
This method is not intended to be called by application code directly.
Instead, the DateTime.with(WithAdjuster)
method should be used:
Implementations must use the methods on DateTime
to make the adjustment.
The returned object must have the same observable type as this object.
The input object will be mutated if it is mutable, or a new object returned if immutable.
This interface can be used by calendar systems other than ISO. Implementations may choose to document compatibility with other calendar systems, or validate for it by querying the calendar system from the input object.
doAdjustment
in interface DateTime.WithAdjuster
dateTime
- the date-time object to adjust, not nullpublic long periodUntil(DateTime endDateTime, PeriodUnit unit)
DateTime
This is used to calculate the period between two date-times.
This method operates in association with PeriodUnit.between(R, R)
.
That method returns an object which can be used directly in addition/subtraction
whereas this method returns the amount directly:
long period = start.periodUntil(end, MONTHS); // this method long period = MONTHS.between(start, end).getAmount(); // same as above dateTime.plus(MONTHS.between(start, end)); // directly add
periodUntil
in interface DateTime
endDateTime
- the end date-time, of the same type as this object, not nullunit
- the unit to measure the period in, not nullpublic long toEpochDay()
LocalDate
to Epoch Days.
The Epoch Day count is a simple incrementing count of days where day 0 is 1970-01-01.
public int compareTo(LocalDate other)
LocalDate
to another date.
The comparison is based on the time-line position of the dates.
compareTo
in interface Comparable<LocalDate>
other
- the other date to compare to, not nullpublic boolean isAfter(LocalDate other)
LocalDate
is after the specified date.
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean isBefore(LocalDate other)
LocalDate
is before the specified date.
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean equals(Object obj)
The comparison is based on the time-line position of the dates.
Only objects of type LocalDate
are compared, other types return false.
To compare the date of two DateTimeAccessor
instances, use
LocalDateTimeField.EPOCH_DAY
as a comparator.
public int hashCode()
public String toString()
String
, such as 2007-12-03
.
The output will be in the ISO-8601 format yyyy-MM-dd
.
public String toString(CalendricalFormatter formatter)
String
using the formatter.formatter
- the formatter to use, not nullUnsupportedOperationException
- if the formatter cannot printDateTimeException
- if an error occurs during printing