public final class LocalDateTime extends Object implements Calendrical, DateTimeProvider, Comparable<LocalDateTime>, CalendricalMatcher, DateAdjuster, TimeAdjuster, Serializable
2007-12-03T10:15:30
.
LocalDateTime
is an immutable calendrical that represents a date-time, often
viewed as year-month-day-hour-minute-second. This object can also access other
fields such as day-of-year, day-of-week and week-of-year.
This class stores all date and time fields, to a precision of nanoseconds.
It does not store or represent a time-zone. Thus, for example, the value
"2nd October 2007 at 13:45.30.123456789" can be stored in an LocalDateTime
.
LocalDateTime is immutable and thread-safe.
Modifier and Type | Method and Description |
---|---|
LocalDate |
adjustDate(LocalDate date)
Adjusts a date to have the value of the date part of this object.
|
LocalTime |
adjustTime(LocalTime time)
Adjusts a time to have the value of the time part of this object.
|
OffsetDateTime |
atOffset(ZoneOffset offset)
Returns an offset date-time formed from this date-time and the specified offset.
|
ZonedDateTime |
atZone(TimeZone zone)
Returns a zoned date-time formed from this date-time and the specified time-zone.
|
ZonedDateTime |
atZone(TimeZone zone,
ZoneResolver resolver)
Returns a zoned date-time formed from this date-time and the specified time-zone
taking control of what occurs in time-line gaps and overlaps.
|
int |
compareTo(LocalDateTime other)
Compares this
LocalDateTime to another date-time. |
boolean |
equals(Object other)
Checks if this
LocalDateTime is equal to the specified date-time. |
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
ISOChronology |
getChronology()
Gets the chronology that this date-time uses, 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.
|
int |
getHourOfDay()
Gets the hour-of-day field.
|
int |
getMinuteOfHour()
Gets the minute-of-hour field.
|
MonthOfYear |
getMonthOfYear()
Gets the month-of-year field, which is an enum
MonthOfYear . |
int |
getNanoOfSecond()
Gets the nano-of-second field.
|
int |
getSecondOfMinute()
Gets the second-of-minute field.
|
int |
getYear()
Gets the year field.
|
int |
hashCode()
A hash code for this
LocalDateTime . |
boolean |
isAfter(LocalDateTime other)
Checks if this
LocalDateTime is after the specified date-time. |
boolean |
isBefore(LocalDateTime other)
Checks if this
LocalDateTime is before the specified date-time. |
boolean |
isLeapYear()
Checks if the year is a leap year, according to the ISO proleptic
calendar system rules.
|
boolean |
matches(CalendricalMatcher matcher)
Checks whether this
LocalDateTime matches the specified matcher. |
boolean |
matchesCalendrical(Calendrical calendrical)
Checks if the date-time extracted from the calendrical matches this.
|
LocalDateTime |
minus(Duration duration)
Returns a copy of this
LocalDateTime with the specified duration subtracted. |
LocalDateTime |
minus(PeriodProvider periodProvider)
Returns a copy of this
LocalDateTime with the specified period subtracted. |
LocalDateTime |
minusDays(long days)
Returns a copy of this
LocalDateTime with the specified period in days subtracted. |
LocalDateTime |
minusHours(long hours)
Returns a copy of this
LocalDateTime with the specified period in hours subtracted. |
LocalDateTime |
minusMinutes(long minutes)
Returns a copy of this
LocalDateTime with the specified period in minutes subtracted. |
LocalDateTime |
minusMonths(long months)
Returns a copy of this
LocalDateTime with the specified period in months subtracted. |
LocalDateTime |
minusMonths(long months,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the specified period in months subtracted. |
LocalDateTime |
minusNanos(long nanos)
Returns a copy of this
LocalDateTime with the specified period in nanoseconds subtracted. |
LocalDateTime |
minusSeconds(long seconds)
Returns a copy of this
LocalDateTime with the specified period in seconds subtracted. |
LocalDateTime |
minusWeeks(long weeks)
Returns a copy of this
LocalDateTime with the specified period in weeks subtracted. |
LocalDateTime |
minusYears(long years)
Returns a copy of this
LocalDateTime with the specified period in years subtracted. |
LocalDateTime |
minusYears(long years,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the specified period in years subtracted. |
static LocalDateTime |
now()
Obtains the current date-time from the system clock in the default time-zone.
|
static LocalDateTime |
now(Clock clock)
Obtains the current date-time from the specified clock.
|
static LocalDateTime |
of(DateProvider dateProvider,
TimeProvider timeProvider)
Obtains an instance of
LocalDateTime from a date and time. |
static LocalDateTime |
of(DateTimeProvider dateTimeProvider)
Obtains an instance of
LocalTime from a date-time provider. |
static LocalDateTime |
of(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour)
Obtains an instance of
LocalDateTime from year, month,
day, hour and minute, setting the second and nanosecond to zero. |
static LocalDateTime |
of(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute)
Obtains an instance of
LocalDateTime from year, month,
day, hour, minute and second, setting the nanosecond to zero. |
static LocalDateTime |
of(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int nanoOfSecond)
Obtains an instance of
LocalDateTime from year, month,
day, hour, minute, second and nanosecond. |
static LocalDateTime |
of(int year,
MonthOfYear monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour)
Obtains an instance of
LocalDateTime from year, month,
day, hour and minute, setting the second and nanosecond to zero. |
static LocalDateTime |
of(int year,
MonthOfYear monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute)
Obtains an instance of
LocalDateTime from year, month,
day, hour, minute and second, setting the nanosecond to zero. |
static LocalDateTime |
of(int year,
MonthOfYear monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int nanoOfSecond)
Obtains an instance of
LocalDateTime from year, month,
day, hour, minute, second and nanosecond. |
static LocalDateTime |
ofMidnight(DateProvider dateProvider)
Obtains an instance of
LocalDateTime from a date with the
time set to midnight at the start of day. |
static LocalDateTime |
ofMidnight(int year,
int monthOfYear,
int dayOfMonth)
Obtains an instance of
LocalDateTime from year, month and
day with the time set to midnight at the start of day. |
static LocalDateTime |
ofMidnight(int year,
MonthOfYear monthOfYear,
int dayOfMonth)
Obtains an instance of
LocalDateTime from year, month and
day with the time set to midnight at the start of day. |
static LocalDateTime |
parse(String text)
Obtains an instance of
LocalDateTime from a text string such as 2007-12-03T10:15:30 . |
static LocalDateTime |
parse(String text,
DateTimeFormatter formatter)
Obtains an instance of
LocalDateTime from a text string using a specific formatter. |
LocalDateTime |
plus(Duration duration)
Returns a copy of this
LocalDateTime with the specified duration added. |
LocalDateTime |
plus(PeriodProvider periodProvider)
Returns a copy of this
LocalDateTime with the specified period added. |
LocalDateTime |
plusDays(long days)
Returns a copy of this
LocalDateTime with the specified period in days added. |
LocalDateTime |
plusHours(long hours)
Returns a copy of this
LocalDateTime with the specified period in hours added. |
LocalDateTime |
plusMinutes(long minutes)
Returns a copy of this
LocalDateTime with the specified period in minutes added. |
LocalDateTime |
plusMonths(long months)
Returns a copy of this
LocalDateTime with the specified period in months added. |
LocalDateTime |
plusMonths(long months,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the specified period in months added. |
LocalDateTime |
plusNanos(long nanos)
Returns a copy of this
LocalDateTime with the specified period in nanoseconds added. |
LocalDateTime |
plusSeconds(long seconds)
Returns a copy of this
LocalDateTime with the specified period in seconds added. |
LocalDateTime |
plusWeeks(long weeks)
Returns a copy of this
LocalDateTime with the specified period in weeks added. |
LocalDateTime |
plusYears(long years)
Returns a copy of this
LocalDateTime with the specified period in years added. |
LocalDateTime |
plusYears(long years,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the specified period in years added. |
static CalendricalRule<LocalDateTime> |
rule()
Gets the rule for
LocalDateTime . |
LocalDate |
toLocalDate()
Converts this date-time to a
LocalDate . |
LocalDateTime |
toLocalDateTime()
Converts this date-time to a
LocalDateTime ,
trivially returning this . |
LocalTime |
toLocalTime()
Converts this date-time to a
LocalTime . |
String |
toString()
Outputs this date-time as a
String , such as 2007-12-03T10:15:30 . |
String |
toString(DateTimeFormatter formatter)
Outputs this date-time as a
String using the formatter. |
LocalDateTime |
with(DateAdjuster adjuster)
Returns a copy of this
LocalDateTime with the date altered using the adjuster. |
LocalDateTime |
with(MonthOfYear monthOfYear)
Returns a copy of this
LocalDateTime with the month-of-year altered. |
LocalDateTime |
with(MonthOfYear monthOfYear,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the month-of-year altered. |
LocalDateTime |
with(TimeAdjuster adjuster)
Returns a copy of this
LocalDateTime with the time altered using the adjuster. |
LocalDateTime |
withDate(int year,
int monthOfYear,
int dayOfMonth)
Returns a copy of this
LocalDateTime with the date values altered. |
LocalDateTime |
withDate(int year,
MonthOfYear monthOfYear,
int dayOfMonth)
Returns a copy of this
LocalDateTime with the date values altered. |
LocalDateTime |
withDayOfMonth(int dayOfMonth)
Returns a copy of this
LocalDateTime with the day-of-month altered. |
LocalDateTime |
withDayOfMonth(int dayOfMonth,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the day-of-month altered. |
LocalDateTime |
withDayOfYear(int dayOfYear)
Returns a copy of this
LocalDateTime with the day-of-year altered. |
LocalDateTime |
withHourOfDay(int hourOfDay)
Returns a copy of this
LocalDateTime with the hour-of-day value altered. |
LocalDateTime |
withMinuteOfHour(int minuteOfHour)
Returns a copy of this
LocalDateTime with the minute-of-hour value altered. |
LocalDateTime |
withMonthOfYear(int monthOfYear)
Returns a copy of this
LocalDateTime with the month-of-year altered. |
LocalDateTime |
withMonthOfYear(int monthOfYear,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the month-of-year altered. |
LocalDateTime |
withNanoOfSecond(int nanoOfSecond)
Returns a copy of this
LocalDateTime with the nano-of-second value altered. |
LocalDateTime |
withSecondOfMinute(int secondOfMinute)
Returns a copy of this
LocalDateTime with the second-of-minute value altered. |
LocalDateTime |
withTime(int hourOfDay,
int minuteOfHour)
Returns a copy of this
LocalDateTime with the time values altered. |
LocalDateTime |
withTime(int hourOfDay,
int minuteOfHour,
int secondOfMinute)
Returns a copy of this
LocalDateTime with the time values altered. |
LocalDateTime |
withTime(int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int nanoOfSecond)
Returns a copy of this
LocalDateTime with the time values altered. |
LocalDateTime |
withYear(int year)
Returns a copy of this
LocalDateTime with the year altered. |
LocalDateTime |
withYear(int year,
DateResolver dateResolver)
Returns a copy of this
LocalDateTime with the year altered. |
public static LocalDateTime now()
This will query the system clock
in the default
time-zone to obtain the current date-time.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
public static LocalDateTime now(Clock clock)
This will query the specified clock to obtain the current date-time.
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 LocalDateTime ofMidnight(int year, MonthOfYear monthOfYear, int dayOfMonth)
LocalDateTime
from year, month and
day with the time set to midnight at the start of day.
The day must be valid for the year and month or an exception will be thrown.
The time fields will be set to zero by this factory method.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime ofMidnight(int year, int monthOfYear, int dayOfMonth)
LocalDateTime
from year, month and
day with the time set to midnight at the start of day.
The day must be valid for the year and month or an exception will be thrown.
The time fields will be set to zero by this factory method.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth
- the day-of-month to represent, from 1 to 31IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime ofMidnight(DateProvider dateProvider)
LocalDateTime
from a date with the
time set to midnight at the start of day.
The day must be valid for the year and month or an exception will be thrown.
The time fields will be set to zero by this factory method.
dateProvider
- the date provider to use, not nullpublic static LocalDateTime of(int year, MonthOfYear monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour)
LocalDateTime
from year, month,
day, hour and minute, setting the second and nanosecond to zero.
The day must be valid for the year and month or an exception will be thrown.
The second and nanosecond fields will be set to zero by this factory method.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime of(int year, MonthOfYear monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute)
LocalDateTime
from year, month,
day, hour, minute and second, setting the nanosecond to zero.
The day must be valid for the year and month or an exception will be thrown.
The nanosecond field will be set to zero by this factory method.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59secondOfMinute
- the second-of-minute to represent, from 0 to 59IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime of(int year, MonthOfYear monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond)
LocalDateTime
from year, month,
day, hour, minute, second and nanosecond.
The day must be valid for the year and month or an exception will be thrown.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59secondOfMinute
- the second-of-minute to represent, from 0 to 59nanoOfSecond
- the nano-of-second to represent, from 0 to 999,999,999IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour)
LocalDateTime
from year, month,
day, hour and minute, setting the second and nanosecond to zero.
The day must be valid for the year and month or an exception will be thrown.
The second and nanosecond fields will be set to zero by this factory method.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth
- the day-of-month to represent, from 1 to 31hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute)
LocalDateTime
from year, month,
day, hour, minute and second, setting the nanosecond to zero.
The day must be valid for the year and month or an exception will be thrown.
The nanosecond field will be set to zero by this factory method.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth
- the day-of-month to represent, from 1 to 31hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59secondOfMinute
- the second-of-minute to represent, from 0 to 59IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond)
LocalDateTime
from year, month,
day, hour, minute, second and nanosecond.
The day must be valid for the year and month or an exception will be thrown.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth
- the day-of-month to represent, from 1 to 31hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59secondOfMinute
- the second-of-minute to represent, from 0 to 59nanoOfSecond
- the nano-of-second to represent, from 0 to 999,999,999IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static LocalDateTime of(DateProvider dateProvider, TimeProvider timeProvider)
LocalDateTime
from a date and time.dateProvider
- the date provider to use, not nulltimeProvider
- the time provider to use, not nullpublic static LocalDateTime of(DateTimeProvider dateTimeProvider)
LocalTime
from a date-time provider.
The purpose of this method is to convert a DateTimeProvider
to a LocalDateTime
in the safest possible way. Specifically,
the means checking whether the input parameter is null and
whether the result of the provider is null.
dateTimeProvider
- the date-time provider to use, not nullpublic static LocalDateTime parse(String text)
LocalDateTime
from a text string such as 2007-12-03T10:15:30
.
The following formats are accepted in ASCII:
{Year}-{MonthOfYear}-{DayOfMonth}T{Hour}:{Minute}
{Year}-{MonthOfYear}-{DayOfMonth}T{Hour}:{Minute}:{Second}
{Year}-{MonthOfYear}-{DayOfMonth}T{Hour}:{Minute}:{Second}.{NanosecondFraction}
The year has between 4 and 10 digits with values from MIN_YEAR to MAX_YEAR. If there are more than 4 digits then the year must be prefixed with the plus symbol. Negative years are allowed, but not negative zero.
The month-of-year has 2 digits with values from 1 to 12.
The day-of-month has 2 digits with values from 1 to 31 appropriate to the month.
The hour has 2 digits with values from 0 to 23. The minute has 2 digits with values from 0 to 59. The second has 2 digits with values from 0 to 59. The nanosecond fraction has from 1 to 9 digits with values from 0 to 999,999,999.
text
- the text to parse such as '2007-12-03T10:15:30', not nullCalendricalException
- if the text cannot be parsedpublic static LocalDateTime parse(String text, DateTimeFormatter formatter)
LocalDateTime
from a text string using a specific formatter.
The text is parsed using the formatter, returning a date-time.
text
- the text to parse, not nullformatter
- the formatter to use, not nullUnsupportedOperationException
- if the formatter cannot parseCalendricalException
- if the text cannot be parsedpublic ISOChronology getChronology()
public <T> T get(CalendricalRule<T> rule)
This method queries the value of the specified calendrical rule.
If the value cannot be returned for the rule from this date-time then
null
will be returned.
get
in interface Calendrical
rule
- the rule to use, not nullpublic int getYear()
This method returns the primitive int
value for the year.
Additional information about the year can be obtained by creating a Year
.
public MonthOfYear getMonthOfYear()
MonthOfYear
.
This method returns the enum MonthOfYear
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
.
Additional information can be obtained from the MonthOfYear
.
This includes month lengths, textual names and access to the quarter-of-year
and month-of-quarter values.
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 int getHourOfDay()
public int getMinuteOfHour()
public int getSecondOfMinute()
public int getNanoOfSecond()
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 ISO8601 standard.
public LocalDateTime with(DateAdjuster adjuster)
LocalDateTime
with the date altered using the adjuster.
Adjusters can be used to alter the date in various ways. 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.
The time does not affect the calculation and will be the same in the result.
This instance is immutable and unaffected by this method call.
adjuster
- the adjuster to use, not nullLocalDateTime
based on this date-time with the date adjusted, never nullNullPointerException
- if the adjuster returned nullpublic LocalDateTime with(TimeAdjuster adjuster)
LocalDateTime
with the time altered using the adjuster.
Adjusters can be used to alter the time in various ways. A simple adjuster might simply set the one of the fields, such as the hour field. A more complex adjuster might set the time to end of the working day.
The date does not affect the calculation and will be the same in the result.
This instance is immutable and unaffected by this method call.
adjuster
- the adjuster to use, not nullLocalDateTime
based on this date-time with the time adjusted, never nullIllegalArgumentException
- if the adjuster returned nullpublic LocalDateTime withYear(int year)
LocalDateTime
with the year altered.
If the resulting LocalDateTime
is invalid, it will be resolved using DateResolvers.previousValid()
.
The time does not affect the calculation and will be the same in the result.
This method does the same as withYear(year, DateResolvers.previousValid())
.
This instance is immutable and unaffected by this method call.
year
- the year to set in the returned date, from MIN_YEAR to MAX_YEARLocalDateTime
based on this date-time with the requested year, never nullIllegalCalendarFieldValueException
- if the year value is invalidpublic LocalDateTime withYear(int year, DateResolver dateResolver)
LocalDateTime
with the year altered.
If the resulting LocalDateTime
is invalid, it will be resolved using dateResolver
.
The time does not affect the calculation and will be the same in the result.
This instance is immutable and unaffected by this method call.
year
- the year to set in the returned date, from MIN_YEAR to MAX_YEARdateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the requested year, never nullIllegalCalendarFieldValueException
- if the year value is invalidpublic LocalDateTime withMonthOfYear(int monthOfYear)
LocalDateTime
with the month-of-year altered.
If the resulting LocalDateTime
is invalid, it will be resolved using DateResolvers.previousValid()
.
The time does not affect the calculation and will be the same in the result.
This method does the same as withMonthOfYear(monthOfYear, DateResolvers.previousValid())
.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to set in the returned date, from 1 (January) to 12 (December)LocalDateTime
based on this date-time with the requested month, never nullIllegalCalendarFieldValueException
- if the month-of-year value is invalidpublic LocalDateTime withMonthOfYear(int monthOfYear, DateResolver dateResolver)
LocalDateTime
with the month-of-year altered.
If the resulting LocalDateTime
is invalid, it will be resolved using dateResolver
.
The time does not affect the calculation and will be the same in the result.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to set in the returned date, from 1 (January) to 12 (December)dateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the requested month, never nullIllegalCalendarFieldValueException
- if the month-of-year value is invalidpublic LocalDateTime with(MonthOfYear monthOfYear)
LocalDateTime
with the month-of-year altered.
If the resulting LocalDateTime
is invalid, it will be resolved using DateResolvers.previousValid()
.
The time does not affect the calculation and will be the same in the result.
This method does the same as with(monthOfYear, DateResolvers.previousValid())
.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to set in the returned date, not nullLocalDateTime
based on this date-time with the requested month, never nullpublic LocalDateTime with(MonthOfYear monthOfYear, DateResolver dateResolver)
LocalDateTime
with the month-of-year altered.
If the resulting LocalDateTime
is invalid, it will be resolved using dateResolver
.
The time does not affect the calculation and will be the same in the result.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to set in the returned date, not nulldateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the requested month, never nullpublic LocalDateTime withDayOfMonth(int dayOfMonth)
LocalDateTime
with the day-of-month altered.
If the resulting LocalDateTime
is invalid, an exception is thrown.
The time does not affect the calculation and will be the same in the result.
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-31LocalDateTime
based on this date-time with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-month value is invalidInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic LocalDateTime withDayOfMonth(int dayOfMonth, DateResolver dateResolver)
LocalDateTime
with the day-of-month altered.
If the resulting LocalDateTime
is invalid, it will be resolved using dateResolver
.
The time does not affect the calculation and will be the same in the result.
This instance is immutable and unaffected by this method call.
dayOfMonth
- the day-of-month to set in the returned date, from 1 to 31dateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-month value is invalidpublic LocalDateTime withDayOfYear(int dayOfYear)
LocalDateTime
with the day-of-year altered.
If the resulting LocalDateTime
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-366LocalDateTime
based on this date with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-year value is invalidInvalidCalendarFieldException
- if the day-of-year is invalid for the yearpublic LocalDateTime withDate(int year, MonthOfYear monthOfYear, int dayOfMonth)
LocalDateTime
with the date values altered.
This method will return a new instance with the same time fields, but altered date fields.
This instance is immutable and unaffected by this method call.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31LocalDateTime
based on this date-time with the requested date, never nullIllegalCalendarFieldValueException
- if any field value is invalidInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic LocalDateTime withDate(int year, int monthOfYear, int dayOfMonth)
LocalDateTime
with the date values altered.
This method will return a new instance with the same time fields, but altered date fields.
This instance is immutable and unaffected by this method call.
year
- the year to represent, from MIN_YEAR to MAX_YEARmonthOfYear
- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth
- the day-of-month to represent, from 1 to 31LocalDateTime
based on this date-time with the requested date, never nullIllegalCalendarFieldValueException
- if any field value is invalidInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic LocalDateTime withHourOfDay(int hourOfDay)
LocalDateTime
with the hour-of-day value altered.
This instance is immutable and unaffected by this method call.
hourOfDay
- the hour-of-day to represent, from 0 to 23LocalDateTime
based on this date-time with the requested hour, never nullIllegalCalendarFieldValueException
- if the hour value is invalidpublic LocalDateTime withMinuteOfHour(int minuteOfHour)
LocalDateTime
with the minute-of-hour value altered.
This instance is immutable and unaffected by this method call.
minuteOfHour
- the minute-of-hour to represent, from 0 to 59LocalDateTime
based on this date-time with the requested minute, never nullIllegalCalendarFieldValueException
- if the minute value is invalidpublic LocalDateTime withSecondOfMinute(int secondOfMinute)
LocalDateTime
with the second-of-minute value altered.
This instance is immutable and unaffected by this method call.
secondOfMinute
- the second-of-minute to represent, from 0 to 59LocalDateTime
based on this date-time with the requested second, never nullIllegalCalendarFieldValueException
- if the second value is invalidpublic LocalDateTime withNanoOfSecond(int nanoOfSecond)
LocalDateTime
with the nano-of-second value altered.
This instance is immutable and unaffected by this method call.
nanoOfSecond
- the nano-of-second to represent, from 0 to 999,999,999LocalDateTime
based on this date-time with the requested nanosecond, never nullIllegalCalendarFieldValueException
- if the nano value is invalidpublic LocalDateTime withTime(int hourOfDay, int minuteOfHour)
LocalDateTime
with the time values altered.
This method will return a new instance with the same date fields,
but altered time fields.
This is a shorthand for withTime(int,int,int,int)
and sets
the second and nanosecond fields to zero.
This instance is immutable and unaffected by this method call.
hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59LocalDateTime
based on this date-time with the requested time, never nullIllegalCalendarFieldValueException
- if any field value is invalidpublic LocalDateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute)
LocalDateTime
with the time values altered.
This method will return a new instance with the same date fields,
but altered time fields.
This is a shorthand for withTime(int,int,int,int)
and sets
the nanosecond fields to zero.
This instance is immutable and unaffected by this method call.
hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59secondOfMinute
- the second-of-minute to represent, from 0 to 59LocalDateTime
based on this date-time with the requested time, never nullIllegalCalendarFieldValueException
- if any field value is invalidpublic LocalDateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond)
LocalDateTime
with the time values altered.
This method will return a new instance with the same date fields, but altered time fields.
This instance is immutable and unaffected by this method call.
hourOfDay
- the hour-of-day to represent, from 0 to 23minuteOfHour
- the minute-of-hour to represent, from 0 to 59secondOfMinute
- the second-of-minute to represent, from 0 to 59nanoOfSecond
- the nano-of-second to represent, from 0 to 999,999,999LocalDateTime
based on this date-time with the requested time, never nullIllegalCalendarFieldValueException
- if any field value is invalidpublic LocalDateTime plus(PeriodProvider periodProvider)
LocalDateTime
with the specified period added.
This adds the specified period to this date-time, returning a new date-time.
Before addition, the period is converted to a Period
using
Period.of(PeriodProvider)
.
The detailed rules for the addition effectively treat the date and time parts of this date-time completely separately during the calculation.
The rules are expressed in four steps:
LocalDate.plus(PeriodProvider)
- which has some complex rulesLocalTime#plusWithOverflow(int, int, int, long)
The effect of this definition is that time periods are always evenly spaced.
For example, adding 5 hours will always result in a date-time one hour later
than adding 4 hours. However, another effect of the definition is that adding
24 hour periods is not the same as adding 1 day periods. See the rules of
date addition
to understand why.
For example, this table shows what happens when for various inputs and periods:
2010-01-30T00:00 plus P1M2DT-5H = 2010-03-01T19:00 2010-01-30T00:00 plus P1M2D = 2010-03-02T00:00 2010-01-30T00:00 plus P1M2DT4H = 2010-03-02T04:00 2010-01-30T00:00 plus P1M1DT-5H = 2010-02-28T19:00 2010-01-30T00:00 plus P1M1D = 2010-03-01T00:00 2010-01-30T00:00 plus P1M1DT4H = 2010-03-01T04:00 2010-01-30T00:00 plus P1MT-5H = 2010-02-27T19:00 2010-01-30T00:00 plus P1M = 2010-02-28T00:00 2010-01-30T00:00 plus P1MT4H = 2010-02-28T04:00 2010-01-30T00:00 plus P1M-1DT-5H = 2010-02-27T19:00 2010-01-30T00:00 plus P1M-1D = 2010-02-28T00:00 2010-01-30T00:00 plus P1M-1DT4H = 2010-02-28T04:00 2010-01-30T00:00 plus P1M-2DT-5H = 2010-02-27T19:00 2010-01-30T00:00 plus P1M-2D = 2010-02-28T00:00 2010-01-30T00:00 plus P1M-2DT4H = 2010-02-28T04:00 2010-01-30T00:00 plus P1M-3DT-5H = 2010-02-26T19:00 2010-01-30T00:00 plus P1M-3D = 2010-02-27T00:00 2010-01-30T00:00 plus P1M-3DT4H = 2010-02-27T04:00
This instance is immutable and unaffected by this method call.
periodProvider
- the period to add, not nullLocalDateTime
based on this date-time with the period added, never nullCalendricalException
- if the specified period cannot be converted to a Period
CalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plus(Duration duration)
LocalDateTime
with the specified duration added.
This adds the specified duration to this date-time, returning a new date-time.
The calculation is equivalent to using plusSeconds(long)
and
plusNanos(long)
on the two parts of the duration.
This instance is immutable and unaffected by this method call.
duration
- the duration to add, not nullLocalDateTime
based on this date-time with the duration added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusYears(long years)
LocalDateTime
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 method does the same as plusYears(years, DateResolvers.previousValid())
.
This instance is immutable and unaffected by this method call.
years
- the years to add, may be negativeLocalDateTime
based on this date-time with the years added, never nullCalendricalException
- if the result exceeds the supported date rangeplusYears(long, javax.time.calendar.DateResolver)
public LocalDateTime plusYears(long years, DateResolver dateResolver)
LocalDateTime
with the specified period in years added.
This method adds the specified amount to the years field in three steps:
dateResolver
if necessaryThis instance is immutable and unaffected by this method call.
years
- the years to add, may be negativedateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the years added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusMonths(long months)
LocalDateTime
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 method does the same as plusMonths(months, DateResolvers.previousValid())
.
This instance is immutable and unaffected by this method call.
months
- the months to add, may be negativeLocalDateTime
based on this date-time with the months added, never nullCalendricalException
- if the result exceeds the supported date rangeplusMonths(long, javax.time.calendar.DateResolver)
public LocalDateTime plusMonths(long months, DateResolver dateResolver)
LocalDateTime
with the specified period in months added.
This method adds the specified amount to the months field in three steps:
dateResolver
if necessaryThis instance is immutable and unaffected by this method call.
months
- the months to add, may be negativedateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the months added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusWeeks(long weeks)
LocalDateTime
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 the 2009-01-07.
This instance is immutable and unaffected by this method call.
weeks
- the weeks to add, may be negativeLocalDateTime
based on this date-time with the weeks added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusDays(long days)
LocalDateTime
with the specified period in 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 the 2009-01-01.
This instance is immutable and unaffected by this method call.
days
- the days to add, may be negativeLocalDateTime
based on this date-time with the days added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusHours(long hours)
LocalDateTime
with the specified period in hours added.
This instance is immutable and unaffected by this method call.
hours
- the hours to add, may be negativeLocalDateTime
based on this date-time with the hours added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusMinutes(long minutes)
LocalDateTime
with the specified period in minutes added.
This instance is immutable and unaffected by this method call.
minutes
- the minutes to add, may be negativeLocalDateTime
based on this date-time with the minutes added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusSeconds(long seconds)
LocalDateTime
with the specified period in seconds added.
This instance is immutable and unaffected by this method call.
seconds
- the seconds to add, may be negativeLocalDateTime
based on this date-time with the seconds added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime plusNanos(long nanos)
LocalDateTime
with the specified period in nanoseconds added.
This instance is immutable and unaffected by this method call.
nanos
- the nanos to add, may be negativeLocalDateTime
based on this date-time with the nanoseconds added, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minus(PeriodProvider periodProvider)
LocalDateTime
with the specified period subtracted.
This subtracts the specified period from this date-time, returning a new date-time.
Before subtraction, the period is converted to a Period
using
Period.of(PeriodProvider)
.
The detailed rules for the subtraction effectively treat the date and time parts of this date-time completely separately during the calculation.
The rules are expressed in four steps:
LocalDate.minus(PeriodProvider)
- which has some complex rulesLocalTime#minusWithOverflow(int, int, int, long)
The effect of this definition is that time periods are always evenly spaced.
For example, subtracting 5 hours will always result in a date-time one hour earlier
than adding 4 hours. However, another effect of the definition is that subtracting
24 hour periods is not the same as subtracting 1 day periods. See the rules of
date subtraction
to understand why.
For example, this table shows what happens when for various inputs and periods:
2010-03-30T00:00 minus P1M3DT-5H = 2010-02-27T05:00 2010-03-30T00:00 minus P1M3D = 2010-02-27T00:00 2010-03-30T00:00 minus P1M3DT4H = 2010-02-26T20:00 2010-03-30T00:00 minus P1M2DT-5H = 2010-02-28T05:00 2010-03-30T00:00 minus P1M2D = 2010-02-28T00:00 2010-03-30T00:00 minus P1M2DT4H = 2010-02-27T20:00 2010-03-30T00:00 minus P1M1DT-5H = 2010-02-28T05:00 2010-03-30T00:00 minus P1M1D = 2010-02-28T00:00 2010-03-30T00:00 minus P1M1DT4H = 2010-02-27T20:00 2010-03-30T00:00 minus P1MT-5H = 2010-02-28T05:00 2010-03-30T00:00 minus P1M = 2010-02-28T00:00 2010-03-30T00:00 minus P1MT4H = 2010-02-27T20:00 2010-03-30T00:00 minus P1M-1DT-5H = 2010-03-01T05:00 2010-03-30T00:00 minus P1M-1D = 2010-03-01T00:00 2010-03-30T00:00 minus P1M-1DT4H = 2010-02-28T20:00 2010-03-30T00:00 minus P1M-2DT-5H = 2010-03-02T05:00 2010-03-30T00:00 minus P1M-2D = 2010-03-02T00:00 2010-03-30T00:00 minus P1M-2DT4H = 2010-03-01T20:00
This instance is immutable and unaffected by this method call.
periodProvider
- the period to subtract, not nullLocalDateTime
based on this date-time with the period subtracted, never nullCalendricalException
- if the specified period cannot be converted to a Period
CalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minus(Duration duration)
LocalDateTime
with the specified duration subtracted.
This subtracts the specified duration from this date-time, returning a new date-time.
The calculation is equivalent to using minusSeconds(long)
and
minusNanos(long)
on the two parts of the duration.
This instance is immutable and unaffected by this method call.
duration
- the duration to subtract, not nullLocalDateTime
based on this date-time with the duration subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusYears(long years)
LocalDateTime
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 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 method does the same as minusYears(years, DateResolvers.previousValid())
.
This instance is immutable and unaffected by this method call.
years
- the years to subtract, may be negativeLocalDateTime
based on this date-time with the years subtracted, never nullCalendricalException
- if the result exceeds the supported date rangeminusYears(long, javax.time.calendar.DateResolver)
public LocalDateTime minusYears(long years, DateResolver dateResolver)
LocalDateTime
with the specified period in years subtracted.
This method subtracts the specified amount from the years field in three steps:
dateResolver
if necessaryThis instance is immutable and unaffected by this method call.
years
- the years to subtract, may be negativedateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the years subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusMonths(long months)
LocalDateTime
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-04-31. Instead of returning an invalid result, the last valid day of the month, 2007-04-30, is selected instead.
This method does the same as minusMonts(months, DateResolvers.previousValid())
.
This instance is immutable and unaffected by this method call.
months
- the months to subtract, may be negativeLocalDateTime
based on this date-time with the months subtracted, never nullCalendricalException
- if the result exceeds the supported date rangeminusMonths(long, javax.time.calendar.DateResolver)
public LocalDateTime minusMonths(long months, DateResolver dateResolver)
LocalDateTime
with the specified period in months subtracted.
This method subtracts the specified amount from the months field in three steps:
dateResolver
if necessaryThis instance is immutable and unaffected by this method call.
months
- the months to subtract, may be negativedateResolver
- the DateResolver to be used if the resulting date would be invalidLocalDateTime
based on this date-time with the months subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusWeeks(long weeks)
LocalDateTime
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, 2008-12-31 minus one week would result in the 2009-01-07.
This instance is immutable and unaffected by this method call.
weeks
- the weeks to subtract, may be negativeLocalDateTime
based on this date-time with the weeks subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusDays(long days)
LocalDateTime
with the specified period in days subtracted.
This method subtracts the specified amount from 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 minus one day would result in the 2009-01-01.
This instance is immutable and unaffected by this method call.
days
- the days to subtract, may be negativeLocalDateTime
based on this date-time with the days subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusHours(long hours)
LocalDateTime
with the specified period in hours subtracted.
This instance is immutable and unaffected by this method call.
hours
- the hours to subtract, may be negativeLocalDateTime
based on this date-time with the hours subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusMinutes(long minutes)
LocalDateTime
with the specified period in minutes subtracted.
This instance is immutable and unaffected by this method call.
minutes
- the minutes to subtract, may be negativeLocalDateTime
based on this date-time with the minutes subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusSeconds(long seconds)
LocalDateTime
with the specified period in seconds subtracted.
This instance is immutable and unaffected by this method call.
seconds
- the seconds to subtract, may be negativeLocalDateTime
based on this date-time with the seconds subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDateTime minusNanos(long nanos)
LocalDateTime
with the specified period in nanoseconds subtracted.
This instance is immutable and unaffected by this method call.
nanos
- the nanos to subtract, may be negativeLocalDateTime
based on this date-time with the nanoseconds subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic boolean matches(CalendricalMatcher matcher)
LocalDateTime
matches the specified matcher.
Matchers can be used to query the date-time. A simple matcher might simply compare one of the fields, such as the year field. A more complex matcher might check if the date is the last day of the month.
matcher
- the matcher to use, not nullpublic boolean matchesCalendrical(Calendrical calendrical)
This method implements the CalendricalMatcher
interface.
It is intended that applications use matches(javax.time.calendar.CalendricalMatcher)
rather than this method.
matchesCalendrical
in interface CalendricalMatcher
calendrical
- the calendrical to match, not nullpublic LocalDate adjustDate(LocalDate date)
This method implements the DateAdjuster
interface.
It is intended that applications use with(DateAdjuster)
rather than this method.
adjustDate
in interface DateAdjuster
date
- the date to be adjusted, not nullpublic LocalTime adjustTime(LocalTime time)
This method implements the TimeAdjuster
interface.
It is intended that applications use with(TimeAdjuster)
rather than this method.
adjustTime
in interface TimeAdjuster
time
- the time to be adjusted, not nullpublic OffsetDateTime atOffset(ZoneOffset offset)
This merges the two objects - this
and the specified offset -
to form an instance of OffsetDateTime
.
This instance is immutable and unaffected by this method call.
offset
- the offset to use, not nullpublic ZonedDateTime atZone(TimeZone zone)
Time-zone rules, such as daylight savings, mean that not every time on the
local time-line exists. When this method converts the date to a date-time it adjusts
the time and offset according to the ZoneResolvers.postTransition()
rules.
This selects the date-time immediately after a gap and the later offset in overlaps.
Finer control over gaps and overlaps is available in two ways.
If you simply want to use the earlier offset at overlaps then call
ZonedDateTime.withEarlierOffsetAtOverlap()
immediately after this method.
Alternately, pass a specific resolver to atZone(TimeZone, ZoneResolver)
.
This instance is immutable and unaffected by this method call.
zone
- the time-zone to use, not nullpublic ZonedDateTime atZone(TimeZone zone, ZoneResolver resolver)
Time-zone rules, such as daylight savings, mean that not every time on the local time-line exists. When this method converts the date to a date-time it adjusts the time and offset according to the specified zone resolver.
This instance is immutable and unaffected by this method call.
zone
- the time-zone to use, not nullresolver
- the zone resolver to use for gaps and overlaps, not nullCalendricalException
- if the date-time cannot be resolvedpublic LocalDate toLocalDate()
LocalDate
.toLocalDate
in interface DateProvider
public LocalTime toLocalTime()
LocalTime
.toLocalTime
in interface TimeProvider
public LocalDateTime toLocalDateTime()
LocalDateTime
,
trivially returning this
.toLocalDateTime
in interface DateTimeProvider
this
, never nullpublic int compareTo(LocalDateTime other)
LocalDateTime
to another date-time.
The comparison is based on the time-line position of the date-times.
compareTo
in interface Comparable<LocalDateTime>
other
- the other date-time to compare to, not nullpublic boolean isAfter(LocalDateTime other)
LocalDateTime
is after the specified date-time.
The comparison is based on the time-line position of the date-times.
other
- the other date-time to compare to, not nullpublic boolean isBefore(LocalDateTime other)
LocalDateTime
is before the specified date-time.
The comparison is based on the time-line position of the date-times.
other
- the other date-time to compare to, not nullpublic boolean equals(Object other)
LocalDateTime
is equal to the specified date-time.
The comparison is based on the time-line position of the date-times.
public int hashCode()
LocalDateTime
.public String toString()
String
, such as 2007-12-03T10:15:30
.
The output will be one of the following formats:
yyyy-MM-dd'T'HH:mm
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd'T'HH:mm:ssfnnn
yyyy-MM-dd'T'HH:mm:ssfnnnnnn
yyyy-MM-dd'T'HH:mm:ssfnnnnnnnnn
public String toString(DateTimeFormatter formatter)
String
using the formatter.formatter
- the formatter to use, not nullUnsupportedOperationException
- if the formatter cannot printCalendricalPrintException
- if an error occurs during printingpublic static CalendricalRule<LocalDateTime> rule()
LocalDateTime
.Copyright © 2014. All rights reserved.