implements Temporal TemporalAdjuster Comparable<OffsetDateTime> Serializable
A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system,
such as 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/Greenwich. For example, the value
"2nd October 2007 at 13:45.30.123456789 +02:00" can be stored in an OffsetDateTime
.
OffsetDateTime
, ZonedDateTime
and Instant
all store an instant
on the time-line to nanosecond precision.
Instant
is the simplest, simply representing the instant.
OffsetDateTime
adds to the instant the offset from UTC/Greenwich, which allows
the local date-time to be obtained.
ZonedDateTime
adds full time-zone rules.
It is intended that ZonedDateTime
or Instant
is used to model data
in simpler applications. This class may be used when modeling date-time concepts in
more detail, or when communicating to a database or in a network protocol.
Field Summary
public static final OffsetDateTime | MAX | The maximum supported OffsetDateTime , '+999999999-12-31T23:59:59.999999999-18:00'. |
public static final OffsetDateTime | MIN | The minimum supported OffsetDateTime , '-999999999-01-01T00:00:00+18:00'. |
Public Method Summary
Temporal |
adjustInto(Temporal temporal)
Adjusts the specified temporal object to have the same offset, date
and time as this object.
|
ZonedDateTime |
atZoneSameInstant(ZoneId zone)
Combines this date-time with a time-zone to create a
ZonedDateTime
ensuring that the result has the same instant. |
ZonedDateTime |
atZoneSimilarLocal(ZoneId zone)
Combines this date-time with a time-zone to create a
ZonedDateTime
trying to keep the same local date and time. |
int | |
boolean | |
String | |
static OffsetDateTime | |
int | |
int |
getDayOfMonth()
Gets the day-of-month field.
|
DayOfWeek |
getDayOfWeek()
Gets the day-of-week field, which is an enum
DayOfWeek . |
int |
getDayOfYear()
Gets the day-of-year field.
|
int |
getHour()
Gets the hour-of-day field.
|
long | |
int |
getMinute()
Gets the minute-of-hour field.
|
Month |
getMonth()
Gets the month-of-year field using the
Month enum. |
int |
getMonthValue()
Gets the month-of-year field from 1 to 12.
|
int |
getNano()
Gets the nano-of-second field.
|
ZoneOffset |
getOffset()
Gets the zone offset, such as '+01:00'.
|
int |
getSecond()
Gets the second-of-minute field.
|
int |
getYear()
Gets the year field.
|
int |
hashCode()
A hash code for this date-time.
|
boolean |
isAfter(OffsetDateTime other)
Checks if the instant of this date-time is after that of the specified date-time.
|
boolean |
isBefore(OffsetDateTime other)
Checks if the instant of this date-time is before that of the specified date-time.
|
boolean |
isEqual(OffsetDateTime other)
Checks if the instant of this date-time is equal to that of the specified date-time.
|
boolean | |
boolean | |
OffsetDateTime |
minus(TemporalAmount amountToSubtract)
Returns a copy of this date-time with the specified amount subtracted.
|
OffsetDateTime |
minus(long amountToSubtract, TemporalUnit unit)
Returns a copy of this date-time with the specified amount subtracted.
|
OffsetDateTime |
minusDays(long days)
Returns a copy of this
OffsetDateTime with the specified number of days subtracted. |
OffsetDateTime |
minusHours(long hours)
Returns a copy of this
OffsetDateTime with the specified number of hours subtracted. |
OffsetDateTime |
minusMinutes(long minutes)
Returns a copy of this
OffsetDateTime with the specified number of minutes subtracted. |
OffsetDateTime |
minusMonths(long months)
Returns a copy of this
OffsetDateTime with the specified number of months subtracted. |
OffsetDateTime |
minusNanos(long nanos)
Returns a copy of this
OffsetDateTime with the specified number of nanoseconds subtracted. |
OffsetDateTime |
minusSeconds(long seconds)
Returns a copy of this
OffsetDateTime with the specified number of seconds subtracted. |
OffsetDateTime |
minusWeeks(long weeks)
Returns a copy of this
OffsetDateTime with the specified number of weeks subtracted. |
OffsetDateTime |
minusYears(long years)
Returns a copy of this
OffsetDateTime with the specified number of years subtracted. |
static OffsetDateTime | |
static OffsetDateTime |
now()
Obtains the current date-time from the system clock in the default time-zone.
|
static OffsetDateTime | |
static OffsetDateTime |
of(LocalDateTime dateTime, ZoneOffset offset)
Obtains an instance of
OffsetDateTime from a date-time and offset. |
static OffsetDateTime |
of(LocalDate date, LocalTime time, ZoneOffset offset)
Obtains an instance of
OffsetDateTime from a date, time and offset. |
static OffsetDateTime |
of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
Obtains an instance of
OffsetDateTime from a year, month, day,
hour, minute, second, nanosecond and offset. |
static OffsetDateTime | |
static OffsetDateTime |
parse(CharSequence text, DateTimeFormatter formatter)
Obtains an instance of
OffsetDateTime from a text string using a specific formatter. |
static OffsetDateTime |
parse(CharSequence text)
Obtains an instance of
OffsetDateTime from a text string
such as 2007-12-03T10:15:30+01:00 . |
OffsetDateTime | |
OffsetDateTime |
plus(long amountToAdd, TemporalUnit unit)
Returns a copy of this date-time with the specified amount added.
|
OffsetDateTime |
plusDays(long days)
Returns a copy of this OffsetDateTime with the specified number of days added.
|
OffsetDateTime |
plusHours(long hours)
Returns a copy of this
OffsetDateTime with the specified number of hours added. |
OffsetDateTime |
plusMinutes(long minutes)
Returns a copy of this
OffsetDateTime with the specified number of minutes added. |
OffsetDateTime |
plusMonths(long months)
Returns a copy of this
OffsetDateTime with the specified number of months added. |
OffsetDateTime |
plusNanos(long nanos)
Returns a copy of this
OffsetDateTime with the specified number of nanoseconds added. |
OffsetDateTime |
plusSeconds(long seconds)
Returns a copy of this
OffsetDateTime with the specified number of seconds added. |
OffsetDateTime |
plusWeeks(long weeks)
Returns a copy of this OffsetDateTime with the specified number of weeks added.
|
OffsetDateTime |
plusYears(long years)
Returns a copy of this
OffsetDateTime with the specified number of years added. |
<R> R | |
ValueRange | |
static Comparator<OffsetDateTime> |
timeLineOrder()
Gets a comparator that compares two
OffsetDateTime instances
based solely on the instant. |
long |
toEpochSecond()
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()
Gets the
LocalDate part of this date-time. |
LocalDateTime |
toLocalDateTime()
Gets the
LocalDateTime part of this date-time. |
LocalTime |
toLocalTime()
Gets the
LocalTime part of this date-time. |
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 . |
ZonedDateTime |
toZonedDateTime()
Converts this date-time to a
ZonedDateTime using the offset as the zone ID. |
OffsetDateTime | |
long |
until(Temporal endExclusive, TemporalUnit unit)
Calculates the amount of time until another date-time in terms of the specified unit.
|
OffsetDateTime |
with(TemporalField field, long newValue)
Returns a copy of this date-time with the specified field set to a new value.
|
OffsetDateTime | |
OffsetDateTime |
withDayOfMonth(int dayOfMonth)
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 |
withHour(int hour)
Returns a copy of this
OffsetDateTime with the hour-of-day altered. |
OffsetDateTime |
withMinute(int minute)
Returns a copy of this
OffsetDateTime with the minute-of-hour altered. |
OffsetDateTime |
withMonth(int month)
Returns a copy of this
OffsetDateTime with the month-of-year altered. |
OffsetDateTime |
withNano(int nanoOfSecond)
Returns a copy of this
OffsetDateTime with the nano-of-second 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 |
withSecond(int second)
Returns a copy of this
OffsetDateTime with the second-of-minute altered. |
OffsetDateTime |
withYear(int year)
Returns a copy of this
OffsetDateTime with the year altered. |
Inherited Method Summary
Fields
public static final OffsetDateTime MAX
The maximum supported OffsetDateTime
, '+999999999-12-31T23:59:59.999999999-18:00'.
This is the local date-time just before midnight at the end of the maximum date
in the minimum offset (larger negative offsets are later on the time-line).
This combines LocalDateTime.MAX
and ZoneOffset.MIN
.
This could be used by an application as a "far future" date-time.
public static final OffsetDateTime MIN
The minimum supported OffsetDateTime
, '-999999999-01-01T00:00:00+18:00'.
This is the local date-time of midnight at the start of the minimum date
in the maximum offset (larger offsets are earlier on the time-line).
This combines LocalDateTime.MIN
and ZoneOffset.MAX
.
This could be used by an application as a "far past" date-time.
Public Methods
public Temporal adjustInto (Temporal temporal)
Adjusts the specified temporal object to have the same offset, date and time as this object.
This returns a temporal object of the same observable type as the input with the offset, date and time changed to be the same as this.
The adjustment is equivalent to using Temporal.with(TemporalField, long)
three times, passing ChronoField.EPOCH_DAY
,
ChronoField.NANO_OF_DAY
and ChronoField.OFFSET_SECONDS
as the fields.
In most cases, it is clearer to reverse the calling pattern by using
Temporal.with(TemporalAdjuster)
:
// these two lines are equivalent, but the second approach is recommended temporal = thisOffsetDateTime.adjustInto(temporal); temporal = temporal.with(thisOffsetDateTime);
This instance is immutable and unaffected by this method call.
Parameters
temporal | the target object to be adjusted, not null |
---|
Returns
- the adjusted object, not null
Throws
DateTimeException | if unable to make the adjustment |
---|---|
ArithmeticException | if numeric overflow occurs |
public ZonedDateTime atZoneSameInstant (ZoneId zone)
Combines this date-time with a time-zone to create a ZonedDateTime
ensuring that the result has the same instant.
This returns a ZonedDateTime
formed from this date-time and the specified time-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(ZoneId)
.
To use the offset as the zone ID, use toZonedDateTime()
.
Parameters
zone | the time-zone to use, not null |
---|
Returns
- the zoned date-time formed from this date-time, not null
public ZonedDateTime atZoneSimilarLocal (ZoneId zone)
Combines this date-time with a time-zone to create a ZonedDateTime
trying to keep the same local date and time.
This returns a ZonedDateTime
formed from this date-time and the specified time-zone.
Where possible, the result will have the same local date-time as this object.
Time-zone rules, such as daylight savings, mean that not every time on the
local time-line exists. If the local date-time is in a gap or overlap according to
the rules then a resolver is used to determine the resultant local time and offset.
This method uses ZonedDateTime.ofLocal(LocalDateTime, ZoneId, ZoneOffset)
to retain the offset from this instance if possible.
Finer control over gaps and overlaps is available in two ways.
If you simply want to use the later offset at overlaps then call
ZonedDateTime.withLaterOffsetAtOverlap()
immediately after this method.
To create a zoned date-time at the same instant irrespective of the local time-line,
use atZoneSameInstant(ZoneId)
.
To use the offset as the zone ID, use toZonedDateTime()
.
Parameters
zone | the time-zone to use, not null |
---|
Returns
- the zoned date-time formed from this date and the earliest valid time for the zone, not null
public int compareTo (OffsetDateTime other)
Compares this date-time to another date-time.
The comparison is based on the instant then on the local date-time.
It is "consistent with equals", as defined by Comparable
.
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()
.Parameters
other | the other date-time to compare to, not null |
---|
Returns
- the comparator value, negative if less, positive if greater
public boolean equals (Object obj)
Checks if this date-time is equal to another date-time.
The comparison is based on the local date-time and the offset.
To compare for the same instant on the time-line, use isEqual(OffsetDateTime)
.
Only objects of type OffsetDateTime
are compared, other types return false.
Parameters
obj | the object to check, null returns false |
---|
Returns
- true if this is equal to the other date-time
public String format (DateTimeFormatter formatter)
Formats this date-time using the specified formatter.
This date-time will be passed to the formatter to produce a string.
Parameters
formatter | the formatter to use, not null |
---|
Returns
- the formatted date-time string, not null
Throws
DateTimeException | if an error occurs during printing |
---|
public static OffsetDateTime from (TemporalAccessor temporal)
Obtains an instance of OffsetDateTime
from a temporal object.
This obtains an offset date-time based on the specified temporal.
A TemporalAccessor
represents an arbitrary set of date and time information,
which this factory converts to an instance of OffsetDateTime
.
The conversion will first obtain a ZoneOffset
from the temporal object.
It will then try to obtain a LocalDateTime
, falling back to an Instant
if necessary.
The result will be the combination of ZoneOffset
with either
with LocalDateTime
or Instant
.
Implementations are permitted to perform optimizations such as accessing
those fields that are equivalent to the relevant objects.
This method matches the signature of the functional interface TemporalQuery
allowing it to be used as a query via method reference, OffsetDateTime::from
.
Parameters
temporal | the temporal object to convert, not null |
---|
Returns
- the offset date-time, not null
Throws
DateTimeException | if unable to convert to an OffsetDateTime
|
---|
public int get (TemporalField field)
Gets the value of the specified field from this date-time as an int
.
This queries this date-time for the value of the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField
then the query is implemented here.
The supported fields
will return valid
values based on this date-time, except NANO_OF_DAY
, MICRO_OF_DAY
,
EPOCH_DAY
, PROLEPTIC_MONTH
and INSTANT_SECONDS
which are too
large to fit in an int
and throw a DateTimeException
.
All other ChronoField
instances will throw an UnsupportedTemporalTypeException
.
If the field is not a ChronoField
, then the result of this method
is obtained by invoking TemporalField.getFrom(TemporalAccessor)
passing this
as the argument. Whether the value can be obtained,
and what the value represents, is determined by the field.
Parameters
field | the field to get, not null |
---|
Returns
- the value for the field
Throws
DateTimeException | if a value for the field cannot be obtained or the value is outside the range of valid values for the field |
---|---|
UnsupportedTemporalTypeException | if the field is not supported or
the range of values exceeds an int |
ArithmeticException | if numeric overflow occurs |
public int getDayOfMonth ()
Gets the day-of-month field.
This method returns the primitive int
value for the day-of-month.
Returns
- the day-of-month, from 1 to 31
public DayOfWeek getDayOfWeek ()
Gets the day-of-week field, which is an enum 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.
Returns
- the day-of-week, not null
public int getDayOfYear ()
Gets the day-of-year field.
This method returns the primitive int
value for the day-of-year.
Returns
- the day-of-year, from 1 to 365, or 366 in a leap year
public int getHour ()
Gets the hour-of-day field.
Returns
- the hour-of-day, from 0 to 23
public long getLong (TemporalField field)
Gets the value of the specified field from this date-time as a long
.
This queries this date-time for the value of the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField
then the query is implemented here.
The supported fields
will return valid
values based on this date-time.
All other ChronoField
instances will throw an UnsupportedTemporalTypeException
.
If the field is not a ChronoField
, then the result of this method
is obtained by invoking TemporalField.getFrom(TemporalAccessor)
passing this
as the argument. Whether the value can be obtained,
and what the value represents, is determined by the field.
Parameters
field | the field to get, not null |
---|
Returns
- the value for the field
Throws
DateTimeException | if a value for the field cannot be obtained |
---|---|
UnsupportedTemporalTypeException | if the field is not supported |
ArithmeticException | if numeric overflow occurs |
public int getMinute ()
Gets the minute-of-hour field.
Returns
- the minute-of-hour, from 0 to 59
public Month getMonth ()
public int getMonthValue ()
Gets the month-of-year field from 1 to 12.
This method returns the month as an int
from 1 to 12.
Application code is frequently clearer if the enum Month
is used by calling getMonth()
.
Returns
- the month-of-year, from 1 to 12
See Also
public int getNano ()
Gets the nano-of-second field.
Returns
- the nano-of-second, from 0 to 999,999,999
public ZoneOffset getOffset ()
Gets the zone offset, such as '+01:00'.
This is the offset of the local date-time from UTC/Greenwich.
Returns
- the zone offset, not null
public int getSecond ()
Gets the second-of-minute field.
Returns
- the second-of-minute, from 0 to 59
public int getYear ()
Gets the year field.
This method returns the primitive int
value for the year.
The year returned by this method is proleptic as per get(YEAR)
.
To obtain the year-of-era, use get(YEAR_OF_ERA)
.
Returns
- the year, from MIN_YEAR to MAX_YEAR
public int hashCode ()
A hash code for this date-time.
Returns
- a suitable hash code
public boolean isAfter (OffsetDateTime other)
Checks if the instant of this date-time is after that of the specified date-time.
This method differs from the comparison in Comparable.compareTo(T)
and equals(Object)
in that it
only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().isAfter(dateTime2.toInstant());
.
Parameters
other | the other date-time to compare to, not null |
---|
Returns
- true if this is after the instant of the specified date-time
public boolean isBefore (OffsetDateTime other)
Checks if the instant of this date-time is before that of the specified date-time.
This method differs from the comparison in Comparable.compareTo(T)
in that it
only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().isBefore(dateTime2.toInstant());
.
Parameters
other | the other date-time to compare to, not null |
---|
Returns
- true if this is before the instant of the specified date-time
public boolean isEqual (OffsetDateTime other)
Checks if the instant of this date-time is equal to that of the specified date-time.
This method differs from the comparison in Comparable.compareTo(T)
and equals(Object)
in that it only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().equals(dateTime2.toInstant());
.
Parameters
other | the other date-time to compare to, not null |
---|
Returns
- true if the instant equals the instant of the specified date-time
public boolean isSupported (TemporalUnit unit)
Checks if the specified unit is supported.
This checks if the specified unit can be added to, or subtracted from, this date-time.
If false, then calling the plus(long, TemporalUnit)
and
minus
methods will throw an exception.
If the unit is a ChronoUnit
then the query is implemented here.
The supported units are:
NANOS
MICROS
MILLIS
SECONDS
MINUTES
HOURS
HALF_DAYS
DAYS
WEEKS
MONTHS
YEARS
DECADES
CENTURIES
MILLENNIA
ERAS
ChronoUnit
instances will return false.
If the unit is not a ChronoUnit
, then the result of this method
is obtained by invoking TemporalUnit.isSupportedBy(Temporal)
passing this
as the argument.
Whether the unit is supported is determined by the unit.
Parameters
unit | the unit to check, null returns false |
---|
Returns
- true if the unit can be added/subtracted, false if not
public boolean isSupported (TemporalField field)
Checks if the specified field is supported.
This checks if this date-time can be queried for the specified field.
If false, then calling the range
,
get
and with(TemporalField, long)
methods will throw an exception.
If the field is a ChronoField
then the query is implemented here.
The supported fields are:
NANO_OF_SECOND
NANO_OF_DAY
MICRO_OF_SECOND
MICRO_OF_DAY
MILLI_OF_SECOND
MILLI_OF_DAY
SECOND_OF_MINUTE
SECOND_OF_DAY
MINUTE_OF_HOUR
MINUTE_OF_DAY
HOUR_OF_AMPM
CLOCK_HOUR_OF_AMPM
HOUR_OF_DAY
CLOCK_HOUR_OF_DAY
AMPM_OF_DAY
DAY_OF_WEEK
ALIGNED_DAY_OF_WEEK_IN_MONTH
ALIGNED_DAY_OF_WEEK_IN_YEAR
DAY_OF_MONTH
DAY_OF_YEAR
EPOCH_DAY
ALIGNED_WEEK_OF_MONTH
ALIGNED_WEEK_OF_YEAR
MONTH_OF_YEAR
PROLEPTIC_MONTH
YEAR_OF_ERA
YEAR
ERA
INSTANT_SECONDS
OFFSET_SECONDS
ChronoField
instances will return false.
If the field is not a ChronoField
, then the result of this method
is obtained by invoking TemporalField.isSupportedBy(TemporalAccessor)
passing this
as the argument.
Whether the field is supported is determined by the field.
Parameters
field | the field to check, null returns false |
---|
Returns
- true if the field is supported on this date-time, false if not
public OffsetDateTime minus (TemporalAmount amountToSubtract)
Returns a copy of this date-time with the specified amount subtracted.
This returns an OffsetDateTime
, based on this one, with the specified amount subtracted.
The amount is typically Period
or Duration
but may be
any other type implementing the TemporalAmount
interface.
The calculation is delegated to the amount object by calling
TemporalAmount.subtractFrom(Temporal)
. The amount implementation is free
to implement the subtraction in any way it wishes, however it typically
calls back to minus(long, TemporalUnit)
. Consult the documentation
of the amount implementation to determine if it can be successfully subtracted.
This instance is immutable and unaffected by this method call.
Parameters
amountToSubtract | the amount to subtract, not null |
---|
Returns
- an
OffsetDateTime
based on this date-time with the subtraction made, not null
Throws
DateTimeException | if the subtraction cannot be made |
---|---|
ArithmeticException | if numeric overflow occurs |
public OffsetDateTime minus (long amountToSubtract, TemporalUnit unit)
Returns a copy of this date-time with the specified amount subtracted.
This returns an OffsetDateTime
, based on this one, with the amount
in terms of the unit subtracted. If it is not possible to subtract the amount,
because the unit is not supported or for some other reason, an exception is thrown.
This method is equivalent to plus(long, TemporalUnit)
with the amount negated.
See that method for a full description of how addition, and thus subtraction, works.
This instance is immutable and unaffected by this method call.
Parameters
amountToSubtract | the amount of the unit to subtract from the result, may be negative |
---|---|
unit | the unit of the amount to subtract, not null |
Returns
- an
OffsetDateTime
based on this date-time with the specified amount subtracted, not null
Throws
DateTimeException | if the subtraction cannot be made |
---|---|
UnsupportedTemporalTypeException | if the unit is not supported |
ArithmeticException | if numeric overflow occurs |
public OffsetDateTime minusDays (long days)
Returns a copy of this OffsetDateTime
with the specified number of days subtracted.
This method subtracts the specified amount from the days field decrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.
For example, 2008-12-31 minus one day would result in 2009-01-01.
This instance is immutable and unaffected by this method call.
Parameters
days | the days to subtract, may be negative |
---|
Returns
- an
OffsetDateTime
based on this date-time with the days subtracted, not null
Throws
DateTimeException | if the result exceeds the supported date range |
---|
public OffsetDateTime minusHours (long hours)
Returns a copy of this OffsetDateTime
with the specified number of hours subtracted.
This instance is immutable and unaffected by this method call.
Parameters
hours | the hours to subtract, may be negative |
---|
Returns
- an
OffsetDateTime
based on this date-time with the hours subtracted, not null
Throws
DateTimeException | if the result exceeds the supported date range |
---|
public OffsetDateTime minusMinutes (long minutes)
Returns a copy of this OffsetDateTime
with the specified number of minutes subtracted.
This instance is immutable and unaffected by this method call.
Parameters
minutes | the minutes to subtract, may be negative |
---|
Returns
- an
OffsetDateTime
based on this date-time with the minutes subtracted, not null
Throws
DateTimeException | if the result exceeds the supported date range |
---|
public OffsetDateTime minusMonths (long months)
Returns a copy of this OffsetDateTime
with the specified number of months subtracted.
This method subtracts the specified amount from the months field in three steps:
- Subtract the input months from the month-of-year field
- Check if the resulting date would be invalid
- Adjust the day-of-month to the last valid day if necessary
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 instance is immutable and unaffected by this method call.
Parameters
months | the months to subtract, may be negative |
---|
Returns
- an
OffsetDateTime
based on this date-time with the months subtracted, not null
Throws
DateTimeException | if the result exceeds the supported date range |
---|
public OffsetDateTime minusNanos (long nanos)
Returns a copy of this OffsetDateTime
with the specified number of nanoseconds subtracted.
This instance is immutable and unaffected by this method call.
Parameters
nanos | the nanos to subtract, may be negative |
---|
Returns
- an
OffsetDateTime
based on this date-time with the nanoseconds subtracted, not null