public final class OffsetDateTime extends Object implements Calendrical, InstantProvider, DateTimeProvider, CalendricalMatcher, DateAdjuster, TimeAdjuster, Comparable<OffsetDateTime>, Serializable
2007-12-03T10:15:30+01:00
.
OffsetDateTime
is an immutable representation of a date-time with an offset.
This class stores all date and time fields, to a precision of nanoseconds,
as well as the offset from UTC. Thus, for example, the value
"2nd October 2007 at 13:45.30.123456789 +02:00" can be stored in an OffsetDateTime
.
OffsetDateTime 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.
|
ZonedDateTime |
atZoneSameInstant(TimeZone zone)
Returns a zoned date-time formed from the instant represented by this
date-time and the specified time-zone.
|
ZonedDateTime |
atZoneSimilarLocal(TimeZone zone)
Returns a zoned date-time formed from this date-time and the specified time-zone.
|
ZonedDateTime |
atZoneSimilarLocal(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(OffsetDateTime other)
Compares this
OffsetDateTime to another date-time. |
boolean |
equalInstant(OffsetDateTime other)
Checks if the instant of this
OffsetDateTime is equal to that of the specified date-time. |
boolean |
equals(Object other)
Checks if this
OffsetDateTime 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.
|
ZoneOffset |
getOffset()
Gets the zone offset.
|
int |
getSecondOfMinute()
Gets the second-of-minute field.
|
int |
getYear()
Gets the year field.
|
int |
hashCode()
A hash code for this
OffsetDateTime . |
boolean |
isAfter(OffsetDateTime other)
Checks if the instant of this
OffsetDateTime is after that of the specified date-time. |
boolean |
isBefore(OffsetDateTime other)
Checks if the instant of this
OffsetDateTime is before that of 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
OffsetDateTime matches the specified matcher. |
boolean |
matchesCalendrical(Calendrical calendrical)
Checks if the date-time extracted from the calendrical matches this.
|
OffsetDateTime |
minus(Duration duration)
Returns a copy of this
OffsetDateTime with the specified duration subtracted. |
OffsetDateTime |
minus(PeriodProvider periodProvider)
Returns a copy of this
OffsetDateTime with the specified period subtracted. |
OffsetDateTime |
minusDays(long days)
Returns a copy of this
OffsetDateTime with the specified period in days subtracted. |
OffsetDateTime |
minusHours(long hours)
Returns a copy of this
OffsetDateTime with the specified period in hours subtracted. |
OffsetDateTime |
minusMinutes(long minutes)
Returns a copy of this
OffsetDateTime with the specified period in minutes subtracted. |
OffsetDateTime |
minusMonths(long months)
Returns a copy of this
OffsetDateTime with the specified period in months subtracted. |
OffsetDateTime |
minusMonths(long months,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the specified period in months subtracted. |
OffsetDateTime |
minusNanos(long nanos)
Returns a copy of this
OffsetDateTime with the specified period in nanoseconds subtracted. |
OffsetDateTime |
minusSeconds(long seconds)
Returns a copy of this
OffsetDateTime with the specified period in seconds subtracted. |
OffsetDateTime |
minusWeeks(long weeks)
Returns a copy of this
OffsetDateTime with the specified period in weeks subtracted. |
OffsetDateTime |
minusYears(long years)
Returns a copy of this
OffsetDateTime with the specified period in years subtracted. |
OffsetDateTime |
minusYears(long years,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the specified period in years subtracted. |
static OffsetDateTime |
now()
Obtains the current date-time from the system clock in the default time-zone.
|
static OffsetDateTime |
now(Clock clock)
Obtains the current date-time from the specified clock.
|
static OffsetDateTime |
of(DateProvider dateProvider,
OffsetTime offsetTime)
Obtains an instance of
OffsetDateTime from a DateProvider
and OffsetTime . |
static OffsetDateTime |
of(DateProvider dateProvider,
TimeProvider timeProvider,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from a date, time and zone offset. |
static OffsetDateTime |
of(DateTimeProvider dateTimeProvider,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from a date-time provider. |
static OffsetDateTime |
of(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int nanoOfSecond,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month,
day, hour, minute, second and nanosecond. |
static OffsetDateTime |
of(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month,
day, hour, minute and second, setting the nanosecond to zero. |
static OffsetDateTime |
of(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month,
day, hour and minute, setting the second and nanosecond to zero. |
static OffsetDateTime |
of(int year,
MonthOfYear monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int nanoOfSecond,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month,
day, hour, minute, second and nanosecond. |
static OffsetDateTime |
of(int year,
MonthOfYear monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month,
day, hour, minute and second, setting the nanosecond to zero. |
static OffsetDateTime |
of(int year,
MonthOfYear monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month,
day, hour and minute, setting the second and nanosecond to zero. |
static OffsetDateTime |
ofEpochSeconds(long epochSeconds,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime using seconds from the
epoch of 1970-01-01T00:00:00Z. |
static OffsetDateTime |
ofInstant(InstantProvider instantProvider,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from an InstantProvider . |
static OffsetDateTime |
ofMidnight(DateProvider dateProvider,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from a date with the
time set to midnight at the start of day. |
static OffsetDateTime |
ofMidnight(int year,
int monthOfYear,
int dayOfMonth,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month and
day with the time set to midnight at the start of day. |
static OffsetDateTime |
ofMidnight(int year,
MonthOfYear monthOfYear,
int dayOfMonth,
ZoneOffset offset)
Obtains an instance of
OffsetDateTime from year, month and
day with the time set to midnight at the start of day. |
static OffsetDateTime |
parse(String text)
Obtains an instance of
OffsetDateTime from a text string such as 2007-12-03T10:15:30+01:00 . |
static OffsetDateTime |
parse(String text,
DateTimeFormatter formatter)
Obtains an instance of
OffsetDateTime from a text string using a specific formatter. |
OffsetDateTime |
plus(Duration duration)
Returns a copy of this
OffsetDateTime with the specified duration added. |
OffsetDateTime |
plus(PeriodProvider periodProvider)
Returns a copy of this
OffsetDateTime with the specified period added. |
OffsetDateTime |
plusDays(long days)
Returns a copy of this OffsetDateTime with the specified period in days added.
|
OffsetDateTime |
plusHours(long hours)
Returns a copy of this
OffsetDateTime with the specified period in hours added. |
OffsetDateTime |
plusMinutes(long minutes)
Returns a copy of this
OffsetDateTime with the specified period in minutes added. |
OffsetDateTime |
plusMonths(long months)
Returns a copy of this
OffsetDateTime with the specified period in months added. |
OffsetDateTime |
plusMonths(long months,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the specified period in months added. |
OffsetDateTime |
plusNanos(long nanos)
Returns a copy of this
OffsetDateTime with the specified period in nanoseconds added. |
OffsetDateTime |
plusSeconds(long seconds)
Returns a copy of this
OffsetDateTime with the specified period in seconds added. |
OffsetDateTime |
plusWeeks(long weeks)
Returns a copy of this OffsetDateTime with the specified period in weeks added.
|
OffsetDateTime |
plusYears(long years)
Returns a copy of this
OffsetDateTime with the specified period in years added. |
OffsetDateTime |
plusYears(long years,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the specified period in years added. |
static CalendricalRule<OffsetDateTime> |
rule()
Gets the rule for
OffsetDateTime . |
long |
toEpochSeconds()
Converts this date-time to the number of seconds from the epoch
of 1970-01-01T00:00:00Z.
|
Instant |
toInstant()
Converts this date-time to an
Instant . |
LocalDate |
toLocalDate()
Converts this date-time to a
LocalDate . |
LocalDateTime |
toLocalDateTime()
Converts this date-time to a
LocalDateTime . |
LocalTime |
toLocalTime()
Converts this date-time to a
LocalTime . |
OffsetDate |
toOffsetDate()
Converts this date-time to an
OffsetDate . |
OffsetTime |
toOffsetTime()
Converts this date-time to an
OffsetTime . |
String |
toString()
Outputs this date-time as a
String , such as 2007-12-03T10:15:30+01:00 . |
String |
toString(DateTimeFormatter formatter)
Outputs this date-time as a
String using the formatter. |
OffsetDateTime |
with(DateAdjuster adjuster)
Returns a copy of this OffsetDateTime with the date altered using the adjuster.
|
OffsetDateTime |
with(MonthOfYear monthOfYear)
Returns a copy of this
OffsetDateTime with the month-of-year altered. |
OffsetDateTime |
with(MonthOfYear monthOfYear,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the month-of-year altered. |
OffsetDateTime |
with(TimeAdjuster adjuster)
Returns a copy of this OffsetDateTime with the time altered using the adjuster.
|
OffsetDateTime |
withDate(int year,
int monthOfYear,
int dayOfMonth)
Returns a copy of this
OffsetDateTime with the date values altered. |
OffsetDateTime |
withDate(int year,
MonthOfYear monthOfYear,
int dayOfMonth)
Returns a copy of this
OffsetDateTime with the date values altered. |
OffsetDateTime |
withDateTime(DateTimeProvider dateTimeProvider)
Returns a copy of this
OffsetDateTime with the time altered and the offset retained. |
OffsetDateTime |
withDayOfMonth(int dayOfMonth)
Returns a copy of this
OffsetDateTime with the day-of-month altered. |
OffsetDateTime |
withDayOfMonth(int dayOfMonth,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the day-of-month altered. |
OffsetDateTime |
withDayOfYear(int dayOfYear)
Returns a copy of this
OffsetDateTime with the day-of-year altered. |
OffsetDateTime |
withHourOfDay(int hourOfDay)
Returns a copy of this
OffsetDateTime with the hour-of-day value altered. |
OffsetDateTime |
withMinuteOfHour(int minuteOfHour)
Returns a copy of this
OffsetDateTime with the minute-of-hour value altered. |
OffsetDateTime |
withMonthOfYear(int monthOfYear)
Returns a copy of this
OffsetDateTime with the month-of-year altered. |
OffsetDateTime |
withMonthOfYear(int monthOfYear,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the month-of-year altered. |
OffsetDateTime |
withNanoOfSecond(int nanoOfSecond)
Returns a copy of this
OffsetDateTime with the nano-of-second value altered. |
OffsetDateTime |
withOffsetSameInstant(ZoneOffset offset)
Returns a copy of this
OffsetDateTime with the specified offset ensuring
that the result is at the same instant. |
OffsetDateTime |
withOffsetSameLocal(ZoneOffset offset)
Returns a copy of this
OffsetDateTime with the specified offset ensuring
that the result has the same local date-time. |
OffsetDateTime |
withSecondOfMinute(int secondOfMinute)
Returns a copy of this
OffsetDateTime with the second-of-minute value altered. |
OffsetDateTime |
withTime(int hourOfDay,
int minuteOfHour)
Returns a copy of this
OffsetDateTime with the time values altered. |
OffsetDateTime |
withTime(int hourOfDay,
int minuteOfHour,
int secondOfMinute)
Returns a copy of this
OffsetDateTime with the time values altered. |
OffsetDateTime |
withTime(int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int nanoOfSecond)
Returns a copy of this OffsetDateTime with the time values altered.
|
OffsetDateTime |
withYear(int year)
Returns a copy of this
OffsetDateTime with the year altered. |
OffsetDateTime |
withYear(int year,
DateResolver dateResolver)
Returns a copy of this
OffsetDateTime with the year altered. |
public static OffsetDateTime now()
This will query the system clock
in the default
time-zone to obtain the current date-time.
The offset will be calculated from the time-zone in the clock.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
public static OffsetDateTime now(Clock clock)
This will query the specified clock to obtain the current date-time. The offset will be calculated from the time-zone in the clock.
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 OffsetDateTime ofMidnight(int year, MonthOfYear monthOfYear, int dayOfMonth, ZoneOffset offset)
OffsetDateTime
from year, month and
day with the time set to midnight at the start of day.
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 31offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime ofMidnight(int year, int monthOfYear, int dayOfMonth, ZoneOffset offset)
OffsetDateTime
from year, month and
day with the time set to midnight at the start of day.
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 31offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime ofMidnight(DateProvider dateProvider, ZoneOffset offset)
OffsetDateTime
from a date with the
time set to midnight at the start of day.
The time fields will be set to zero by this factory method.
dateProvider
- the date provider to use, not nulloffset
- the zone offset, not nullpublic static OffsetDateTime of(int year, MonthOfYear monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, ZoneOffset offset)
OffsetDateTime
from year, month,
day, hour and minute, setting the second and nanosecond to zero.
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 59offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime of(int year, MonthOfYear monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, ZoneOffset offset)
OffsetDateTime
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 59offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime of(int year, MonthOfYear monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond, ZoneOffset offset)
OffsetDateTime
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,999offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, ZoneOffset offset)
OffsetDateTime
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 59offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, ZoneOffset offset)
OffsetDateTime
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 59offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond, ZoneOffset offset)
OffsetDateTime
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,999offset
- the zone offset, not nullIllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static OffsetDateTime of(DateProvider dateProvider, TimeProvider timeProvider, ZoneOffset offset)
OffsetDateTime
from a date, time and zone offset.dateProvider
- the date provider to use, not nulltimeProvider
- the time provider to use, not nulloffset
- the zone offset, not nullpublic static OffsetDateTime of(DateTimeProvider dateTimeProvider, ZoneOffset offset)
OffsetDateTime
from a date-time provider.dateTimeProvider
- the date-time provider to use, not nulloffset
- the zone offset, not nullpublic static OffsetDateTime of(DateProvider dateProvider, OffsetTime offsetTime)
OffsetDateTime
from a DateProvider
and OffsetTime
.dateProvider
- the date provider to use, not nulloffsetTime
- the offset time to use, not nullpublic static OffsetDateTime ofInstant(InstantProvider instantProvider, ZoneOffset offset)
OffsetDateTime
from an InstantProvider
.instantProvider
- the instant to convert, not nulloffset
- the zone offset, not nullCalendarConversionException
- if the instant exceeds the supported date rangepublic static OffsetDateTime ofEpochSeconds(long epochSeconds, ZoneOffset offset)
OffsetDateTime
using seconds from the
epoch of 1970-01-01T00:00:00Z.
The nanosecond field is set to zero.
epochSeconds
- the number of seconds from the epoch of 1970-01-01T00:00:00ZCalendricalException
- if the result exceeds the supported rangepublic static OffsetDateTime parse(String text)
OffsetDateTime
from a text string such as 2007-12-03T10:15:30+01:00
.
The following formats are accepted in ASCII:
{Year}-{MonthOfYear}-{DayOfMonth}T{Hour}:{Minute}{OffsetID}
{Year}-{MonthOfYear}-{DayOfMonth}T{Hour}:{Minute}:{Second}{OffsetID}
{Year}-{MonthOfYear}-{DayOfMonth}T{Hour}:{Minute}:{Second}.{NanosecondFraction}{OffsetID}
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.
The offset ID is the normalized form as defined in ZoneOffset
.
text
- the text to parse such as '2007-12-03T10:15:30+01:00', not nullCalendricalException
- if the text cannot be parsedpublic static OffsetDateTime parse(String text, DateTimeFormatter formatter)
OffsetDateTime
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 OffsetDateTime withDateTime(DateTimeProvider dateTimeProvider)
OffsetDateTime
with the time altered and the offset retained.
This method returns an object with the same ZoneOffset
and the specified LocalDateTime
.
No calculation is needed or performed.
dateTimeProvider
- the local date-time to change to, not nullOffsetDateTime
based on this time with the requested time, never nullpublic ZoneOffset getOffset()
public OffsetDateTime withOffsetSameLocal(ZoneOffset offset)
OffsetDateTime
with the specified offset ensuring
that the result has the same local date-time.
This method returns an object with the same LocalDateTime
and the specified ZoneOffset
.
No calculation is needed or performed.
For example, if this time represents 2007-12-03T10:30+02:00
and the offset specified is
+03:00
, then this method will return 2007-12-03T10:30+03:00
.
To take into account the difference between the offsets, and adjust the time fields,
use withOffsetSameInstant(javax.time.calendar.ZoneOffset)
.
This instance is immutable and unaffected by this method call.
offset
- the zone offset to change to, not nullOffsetDateTime
based on this date-time with the requested offset, never nullpublic OffsetDateTime withOffsetSameInstant(ZoneOffset offset)
OffsetDateTime
with the specified offset ensuring
that the result is at the same instant.
This method returns an object with the the specified ZoneOffset
and a LocalDateTime
adjusted by the difference between the two offsets.
This will result in the old and new objects representing the same instant.
This is useful for finding the local time in a different offset.
For example, if this time represents 2007-12-03T10:30+02:00
and the offset specified is
+03:00
, then this method will return 2007-12-03T11:30+03:00
.
To change the offset without adjusting the local time use withOffsetSameLocal(javax.time.calendar.ZoneOffset)
.
This instance is immutable and unaffected by this method call.
offset
- the zone offset to change to, not nullOffsetDateTime
based on this date-time with the requested offset, never nullCalendricalException
- if the result exceeds the supported date rangepublic 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 OffsetDateTime with(DateAdjuster 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 offset and time do 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 nullOffsetDateTime
based on this date-time with the date adjusted, never nullNullPointerException
- if the adjuster returned nullpublic OffsetDateTime with(TimeAdjuster 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 offset and date do 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 nullOffsetDateTime
based on this date-time with the time adjusted, never nullIllegalArgumentException
- if the adjuster returned nullpublic OffsetDateTime withYear(int year)
OffsetDateTime
with the year altered.
If the resulting OffsetDateTime
is invalid, it will be resolved using DateResolvers.previousValid()
.
The offset 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_YEAROffsetDateTime
based on this date-time with the requested year, never nullIllegalCalendarFieldValueException
- if the year value is invalidpublic OffsetDateTime withYear(int year, DateResolver dateResolver)
OffsetDateTime
with the year altered.
If the resulting OffsetDateTime
is invalid, it will be resolved using dateResolver
.
The offset 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 invalidOffsetDateTime
based on this date-time with the requested year, never nullIllegalCalendarFieldValueException
- if the year value is invalidpublic OffsetDateTime withMonthOfYear(int monthOfYear)
OffsetDateTime
with the month-of-year altered.
If the resulting OffsetDateTime
is invalid, it will be resolved using DateResolvers.previousValid()
.
The offset 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)OffsetDateTime
based on this date-time with the requested month, never nullIllegalCalendarFieldValueException
- if the month-of-year value is invalidpublic OffsetDateTime withMonthOfYear(int monthOfYear, DateResolver dateResolver)
OffsetDateTime
with the month-of-year altered.
If the resulting OffsetDateTime
is invalid, it will be resolved using dateResolver
.
The offset 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 invalidOffsetDateTime
based on this date-time with the requested month, never nullIllegalCalendarFieldValueException
- if the month-of-year value is invalidpublic OffsetDateTime with(MonthOfYear monthOfYear)
OffsetDateTime
with the month-of-year altered.
If the resulting OffsetDateTime
is invalid, it will be resolved using DateResolvers.previousValid()
.
The offset 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 nullOffsetDateTime
based on this date-time with the requested month, never nullpublic OffsetDateTime with(MonthOfYear monthOfYear, DateResolver dateResolver)
OffsetDateTime
with the month-of-year altered.
If the resulting OffsetDateTime
is invalid, it will be resolved using dateResolver
.
The offset 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 invalidOffsetDateTime
based on this date-time with the requested month, never nullpublic OffsetDateTime withDayOfMonth(int dayOfMonth)
OffsetDateTime
with the day-of-month altered.
If the resulting OffsetDateTime
is invalid, an exception is thrown.
The offset 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-31OffsetDateTime
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 OffsetDateTime withDayOfMonth(int dayOfMonth, DateResolver dateResolver)
OffsetDateTime
with the day-of-month altered.
If the resulting OffsetDateTime
is invalid, it will be resolved using dateResolver
.
The offset 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 invalidOffsetDateTime
based on this date-time with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-month value is invalidpublic OffsetDateTime withDayOfYear(int dayOfYear)
OffsetDateTime
with the day-of-year altered.
If the resulting OffsetDateTime
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-366OffsetDateTime
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 OffsetDateTime withDate(int year, MonthOfYear monthOfYear, int dayOfMonth)
OffsetDateTime
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 31OffsetDateTime
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 OffsetDateTime withDate(int year, int monthOfYear, int dayOfMonth)
OffsetDateTime
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_VALUE + 1 to MAX_VALUEmonthOfYear
- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth
- the day-of-month to represent, from 1 to 31OffsetDateTime
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 OffsetDateTime withHourOfDay(int hourOfDay)
OffsetDateTime
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 23OffsetDateTime
based on this date-time with the requested hour, never nullIllegalCalendarFieldValueException
- if the hour value is invalidpublic OffsetDateTime withMinuteOfHour(int minuteOfHour)
OffsetDateTime
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 59OffsetDateTime
based on this date-time with the requested minute, never nullIllegalCalendarFieldValueException
- if the minute value is invalidpublic OffsetDateTime withSecondOfMinute(int secondOfMinute)
OffsetDateTime
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 59OffsetDateTime
based on this date-time with the requested second, never nullIllegalCalendarFieldValueException
- if the second value is invalidpublic OffsetDateTime withNanoOfSecond(int nanoOfSecond)
OffsetDateTime
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,999OffsetDateTime
based on this date-time with the requested nanosecond, never nullIllegalCalendarFieldValueException
- if the nanos value is invalidpublic OffsetDateTime withTime(int hourOfDay, int minuteOfHour)
OffsetDateTime
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 59OffsetDateTime
based on this date-time with the requested time, never nullIllegalCalendarFieldValueException
- if any field value is invalidpublic OffsetDateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute)
OffsetDateTime
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 59OffsetDateTime
based on this date-time with the requested time, never nullIllegalCalendarFieldValueException
- if any field value is invalidpublic OffsetDateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond)
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,999OffsetDateTime
based on this date-time with the requested time, never nullIllegalCalendarFieldValueException
- if any field value is invalidpublic OffsetDateTime plus(PeriodProvider periodProvider)
OffsetDateTime
with the specified period added.
This adds the specified period to this date-time, returning a new date-time.
The detailed rules for the addition have some complexity due to variable length months.
See LocalDateTime.plus(PeriodProvider)
for details.
This instance is immutable and unaffected by this method call.
periodProvider
- the period to add, not nullOffsetDateTime
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 OffsetDateTime plus(Duration duration)
OffsetDateTime
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 nullOffsetDateTime
based on this date-time with the duration added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusYears(long years)
OffsetDateTime
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 negativeOffsetDateTime
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 OffsetDateTime plusYears(long years, DateResolver dateResolver)
OffsetDateTime
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 invalidOffsetDateTime
based on this date-time with the years added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusMonths(long months)
OffsetDateTime
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 negativeOffsetDateTime
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 OffsetDateTime plusMonths(long months, DateResolver dateResolver)
OffsetDateTime
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 invalidOffsetDateTime
based on this date-time with the months added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusWeeks(long weeks)
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 negativeOffsetDateTime
based on this date-time with the weeks added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusDays(long days)
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 negativeOffsetDateTime
based on this date-time with the days added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusHours(long hours)
OffsetDateTime
with the specified period in hours added.
This instance is immutable and unaffected by this method call.
hours
- the hours to add, may be negativeOffsetDateTime
based on this date-time with the hours added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusMinutes(long minutes)
OffsetDateTime
with the specified period in minutes added.
This instance is immutable and unaffected by this method call.
minutes
- the minutes to add, may be negativeOffsetDateTime
based on this date-time with the minutes added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusSeconds(long seconds)
OffsetDateTime
with the specified period in seconds added.
This instance is immutable and unaffected by this method call.
seconds
- the seconds to add, may be negativeOffsetDateTime
based on this date-time with the seconds added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime plusNanos(long nanos)
OffsetDateTime
with the specified period in nanoseconds added.
This instance is immutable and unaffected by this method call.
nanos
- the nanos to add, may be negativeOffsetDateTime
based on this date-time with the nanoseconds added, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minus(PeriodProvider periodProvider)
OffsetDateTime
with the specified period subtracted.
This subtracts the specified period from this date-time, returning a new date-time.
The detailed rules for the subtraction have some complexity due to variable length months.
See LocalDateTime.minus(PeriodProvider)
for details.
This instance is immutable and unaffected by this method call.
periodProvider
- the period to subtract, not nullOffsetDateTime
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 OffsetDateTime minus(Duration duration)
OffsetDateTime
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 nullOffsetDateTime
based on this date-time with the duration subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusYears(long years)
OffsetDateTime
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 negativeOffsetDateTime
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 OffsetDateTime minusYears(long years, DateResolver dateResolver)
OffsetDateTime
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 invalidOffsetDateTime
based on this date-time with the years subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusMonths(long months)
OffsetDateTime
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 negativeOffsetDateTime
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 OffsetDateTime minusMonths(long months, DateResolver dateResolver)
OffsetDateTime
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 invalidOffsetDateTime
based on this date-time with the months subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusWeeks(long weeks)
OffsetDateTime
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 negativeOffsetDateTime
based on this date-time with the weeks subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusDays(long days)
OffsetDateTime
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 negativeOffsetDateTime
based on this date-time with the days subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusHours(long hours)
OffsetDateTime
with the specified period in hours subtracted.
This instance is immutable and unaffected by this method call.
hours
- the hours to subtract, may be negativeOffsetDateTime
based on this date-time with the hours subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusMinutes(long minutes)
OffsetDateTime
with the specified period in minutes subtracted.
This instance is immutable and unaffected by this method call.
minutes
- the minutes to subtract, may be negativeOffsetDateTime
based on this date-time with the minutes subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusSeconds(long seconds)
OffsetDateTime
with the specified period in seconds subtracted.
This instance is immutable and unaffected by this method call.
seconds
- the seconds to subtract, may be negativeOffsetDateTime
based on this date-time with the seconds subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic OffsetDateTime minusNanos(long nanos)
OffsetDateTime
with the specified period in nanoseconds subtracted.
This instance is immutable and unaffected by this method call.
nanos
- the nanos to subtract, may be negativeOffsetDateTime
based on this date-time with the nanoseconds subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic boolean matches(CalendricalMatcher matcher)
OffsetDateTime
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 ZonedDateTime atZoneSameInstant(TimeZone zone)
This conversion will ignore the visible local date-time and use the underlying instant instead. This avoids any problems with local time-line gaps or overlaps. The result might have different values for fields such as hour, minute an even day.
To attempt to retain the values of the fields, use atZoneSimilarLocal(TimeZone)
.
This instance is immutable and unaffected by this method call.
zone
- the time-zone to use, not nullpublic ZonedDateTime atZoneSimilarLocal(TimeZone zone)
Time-zone rules, such as daylight savings, mean that not every time on the local time-line exists. As a result, this method can only convert the date-time to the same time if the time-zone rules permit it. If not then a similar time is returned.
This method uses the post transition
rules
to determine what to do when a gap or overlap occurs. These rules select 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 atZoneSimilarLocal(TimeZone, ZoneResolver)
.
To create a zoned date-time at the same instant irrespective of the local time-line,
use atZoneSameInstant(TimeZone)
.
This instance is immutable and unaffected by this method call.
zone
- the time-zone to use, not nullpublic ZonedDateTime atZoneSimilarLocal(TimeZone zone, ZoneResolver resolver)
Time-zone rules, such as daylight savings, mean that not every time on the local time-line exists. As a result, this method can only convert the date-time to the same time if the time-zone rules permit it. If not then a similar time is returned.
This method uses the specified resolver to determine what to do when a gap or overlap occurs.
To create a zoned date-time at the same instant irrespective of the local time-line,
use atZoneSameInstant(TimeZone)
.
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 Instant toInstant()
Instant
.toInstant
in interface InstantProvider
public LocalDate toLocalDate()
LocalDate
.toLocalDate
in interface DateProvider
public LocalTime toLocalTime()
LocalTime
.toLocalTime
in interface TimeProvider
public LocalDateTime toLocalDateTime()
LocalDateTime
.toLocalDateTime
in interface DateTimeProvider
public OffsetDate toOffsetDate()
OffsetDate
.public OffsetTime toOffsetTime()
OffsetTime
.public long toEpochSeconds()
Instants on the time-line after the epoch are positive, earlier are negative.
public int compareTo(OffsetDateTime other)
OffsetDateTime
to another date-time.
The comparison is based on the instant then local date-time.
This ordering is consistent with equals()
.
For example, the following is the comparator order:
2008-12-03T10:30+01:00
2008-12-03T11:00+01:00
2008-12-03T12:00+02:00
2008-12-03T11:30+01:00
2008-12-03T12:00+01:00
2008-12-03T12:30+01:00
equals()
.compareTo
in interface Comparable<OffsetDateTime>
other
- the other date-time to compare to, not nullpublic boolean isAfter(OffsetDateTime other)
OffsetDateTime
is after that of the specified date-time.
This method differs from the comparison in compareTo(javax.time.calendar.OffsetDateTime)
and equals(java.lang.Object)
in that it
only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().isAfter(dateTime2.toInstant());
.
other
- the other date-time to compare to, not nullpublic boolean isBefore(OffsetDateTime other)
OffsetDateTime
is before that of the specified date-time.
This method differs from the comparison in compareTo(javax.time.calendar.OffsetDateTime)
in that it
only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().isBefore(dateTime2.toInstant());
.
other
- the other date-time to compare to, not nullpublic boolean equalInstant(OffsetDateTime other)
OffsetDateTime
is equal to that of the specified date-time.
This method differs from the comparison in compareTo(javax.time.calendar.OffsetDateTime)
and equals(java.lang.Object)
in that it only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().equals(dateTime2.toInstant());
.
other
- the other date-time to compare to, not nullpublic boolean equals(Object other)
OffsetDateTime
is equal to the specified date-time.
This method returns true if the state of the two objects are equal. The state consists of the local date-time and the offset.
To compare for the same instant on the time-line, use equalInstant(javax.time.calendar.OffsetDateTime)
.
public int hashCode()
OffsetDateTime
.public String toString()
String
, such as 2007-12-03T10:15:30+01:00
.
The output will be one of the following formats:
yyyy-MM-dd'T'HH:mmZZZZ
yyyy-MM-dd'T'HH:mm:ssZZZZ
yyyy-MM-dd'T'HH:mm:ssfnnnZZZZ
yyyy-MM-dd'T'HH:mm:ssfnnnnnnZZZZ
yyyy-MM-dd'T'HH:mm:ssfnnnnnnnnnZZZZ
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<OffsetDateTime> rule()
OffsetDateTime
.Copyright © 2014. All rights reserved.