APIdia Launch Partner
Top Description Fields Constructors Methods
java.time

public final Class OffsetTime

extends Object
implements Temporal, TemporalAdjuster, Comparable<OffsetTime>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable, java.time.temporal.TemporalAdjuster, java.time.temporal.Temporal, java.time.temporal.TemporalAccessor
Annotations
@ValueBased
Static Imports
java.time.LocalTime.NANOS_PER_HOUR, .LocalTime.NANOS_PER_MINUTE, .LocalTime.NANOS_PER_SECOND, .LocalTime.SECONDS_PER_DAY, java.time.temporal.ChronoField.NANO_OF_DAY, .ChronoField.OFFSET_SECONDS, .ChronoUnit.NANOS

A time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 10:15:30+01:00.

OffsetTime is an immutable date-time object that represents a time, often viewed as hour-minute-second-offset. This class stores all time fields, to a precision of nanoseconds, as well as a zone offset. For example, the value "13:45:30.123456789+02:00" can be stored in an OffsetTime.

This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. The equals method should be used for comparisons.

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Field Summary

Modifier and TypeField and Description
public static final OffsetTime
MAX

The maximum supported OffsetTime, '23:59:59.999999999-18:00'.

public static final OffsetTime
MIN

The minimum supported OffsetTime, '00:00:00+18:00'.

private final ZoneOffset
private static final long
serialVersionUID

Serialization version.

private final LocalTime

Constructor Summary

AccessConstructor and Description
private
OffsetTime(LocalTime
the local time, not null
time
,
ZoneOffset
the zone offset, not null
offset
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public Temporal

Returns:

the adjusted object, not null
adjustInto
(Temporal
the target object to be adjusted, not null
temporal
)

Implements java.time.temporal.TemporalAdjuster.adjustInto.

Adjusts the specified temporal object to have the same offset and time as this object.

public OffsetDateTime

Returns:

the offset date-time formed from this time and the specified date, not null
atDate
(LocalDate
the date to combine with, not null
date
)

Combines this time with a date to create an OffsetDateTime.

public int

Returns:

the comparator value, that is the comparison of the UTC equivalent other instant, if they are not equal, and if the UTC equivalent other instant is equal, the comparison of this local time with other local time
compareTo
(OffsetTime
the other time to compare to, not null
other
)

Implements java.lang.Comparable.compareTo.

Compares this OffsetTime to another time.

public boolean

Returns:

true if this is equal to the other time
equals
(Object
the object to check, null returns false
obj
)

Overrides java.lang.Object.equals.

Checks if this time is equal to another time.

public String

Returns:

the formatted time string, not null
format
(DateTimeFormatter
the formatter to use, not null
formatter
)

Formats this time using the specified formatter.

public static OffsetTime

Returns:

the offset time, not null
from
(TemporalAccessor
the temporal object to convert, not null
temporal
)

Obtains an instance of OffsetTime from a temporal object.

public int

Returns:

the value for the field
get
(TemporalField
the field to get, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.get.

Gets the value of the specified field from this time as an int.

public int

Returns:

the hour-of-day, from 0 to 23
getHour
()

Gets the hour-of-day field.

public long

Returns:

the value for the field
getLong
(TemporalField
the field to get, not null
field
)

Implements java.time.temporal.TemporalAccessor.getLong.

Gets the value of the specified field from this time as a long.

public int

Returns:

the minute-of-hour, from 0 to 59
getMinute
()

Gets the minute-of-hour field.

public int

Returns:

the nano-of-second, from 0 to 999,999,999
getNano
()

Gets the nano-of-second field.

public ZoneOffset

Returns:

the zone offset, not null
getOffset
()

Gets the zone offset, such as '+01:00'.

public int

Returns:

the second-of-minute, from 0 to 59
getSecond
()

Gets the second-of-minute field.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

A hash code for this time.

public boolean

Returns:

true if this is after the instant of the specified time
isAfter
(OffsetTime
the other time to compare to, not null
other
)

Checks if the instant of this OffsetTime is after that of the specified time applying both times to a common date.

public boolean

Returns:

true if this is before the instant of the specified time
isBefore
(OffsetTime
the other time to compare to, not null
other
)

Checks if the instant of this OffsetTime is before that of the specified time applying both times to a common date.

public boolean

Returns:

true if this is equal to the instant of the specified time
isEqual
(OffsetTime
the other time to compare to, not null
other
)

Checks if the instant of this OffsetTime is equal to that of the specified time applying both times to a common date.

public boolean

Returns:

true if the field is supported on this time, false if not
isSupported
(TemporalField
the field to check, null returns false
field
)

Implements java.time.temporal.TemporalAccessor.isSupported.

Checks if the specified field is supported.

public boolean

Returns:

true if the unit can be added/subtracted, false if not
isSupported
(TemporalUnit
the unit to check, null returns false
unit
)

Implements java.time.temporal.Temporal.isSupported.

Checks if the specified unit is supported.

public OffsetTime

Returns:

an OffsetTime based on this time with the subtraction made, not null
minus
(TemporalAmount
the amount to subtract, not null
amountToSubtract
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this time with the specified amount subtracted.

public OffsetTime

Returns:

an OffsetTime based on this time with the specified amount subtracted, not null
minus
(long
the amount of the unit to subtract from the result, may be negative
amountToSubtract
,
TemporalUnit
the unit of the amount to subtract, not null
unit
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this time with the specified amount subtracted.

public OffsetTime

Returns:

an OffsetTime based on this time with the hours subtracted, not null
minusHours
(long
the hours to subtract, may be negative
hours
)

Returns a copy of this OffsetTime with the specified number of hours subtracted.

public OffsetTime

Returns:

an OffsetTime based on this time with the minutes subtracted, not null
minusMinutes
(long
the minutes to subtract, may be negative
minutes
)

Returns a copy of this OffsetTime with the specified number of minutes subtracted.

public OffsetTime

Returns:

an OffsetTime based on this time with the nanoseconds subtracted, not null
minusNanos
(long
the nanos to subtract, may be negative
nanos
)

Returns a copy of this OffsetTime with the specified number of nanoseconds subtracted.

public OffsetTime

Returns:

an OffsetTime based on this time with the seconds subtracted, not null
minusSeconds
(long
the seconds to subtract, may be negative
seconds
)

Returns a copy of this OffsetTime with the specified number of seconds subtracted.

public static OffsetTime

Returns:

the current time using the system clock and default time-zone, not null
now
()

Obtains the current time from the system clock in the default time-zone.

public static OffsetTime

Returns:

the current time using the system clock, not null
now
(ZoneId
the zone ID to use, not null
zone
)

Obtains the current time from the system clock in the specified time-zone.

public static OffsetTime

Returns:

the current time, not null
now
(Clock
the clock to use, not null
clock
)

Obtains the current time from the specified clock.

public static OffsetTime

Returns:

the offset time, not null
of
(LocalTime
the local time, not null
time
,
ZoneOffset
the zone offset, not null
offset
)

Obtains an instance of OffsetTime from a local time and an offset.

public static OffsetTime

Returns:

the offset time, not null
of
(int
the hour-of-day to represent, from 0 to 23
hour
,
int
the minute-of-hour to represent, from 0 to 59
minute
,
int
the second-of-minute to represent, from 0 to 59
second
,
int
the nano-of-second to represent, from 0 to 999,999,999
nanoOfSecond
,
ZoneOffset
the zone offset, not null
offset
)

Obtains an instance of OffsetTime from an hour, minute, second and nanosecond.

public static OffsetTime

Returns:

the offset time, not null
ofInstant
(Instant
the instant to create the time from, not null
instant
,
ZoneId
the time-zone, which may be an offset, not null
zone
)

Obtains an instance of OffsetTime from an Instant and zone ID.

This creates an offset time with the same instant as that specified.

public static OffsetTime

Returns:

the parsed local time, not null
parse
(CharSequence
the text to parse such as "10:15:30+01:00", not null
text
)

Obtains an instance of OffsetTime from a text string such as 10:15:30+01:00.

public static OffsetTime

Returns:

the parsed offset time, not null
parse
(CharSequence
the text to parse, not null
text
,
DateTimeFormatter
the formatter to use, not null
formatter
)

Obtains an instance of OffsetTime from a text string using a specific formatter.

public OffsetTime

Returns:

an OffsetTime based on this time with the addition made, not null
plus
(TemporalAmount
the amount to add, not null
amountToAdd
)

Overrides default java.time.temporal.Temporal.plus.

Returns a copy of this time with the specified amount added.

public OffsetTime

Returns:

an OffsetTime based on this time with the specified amount added, not null
plus
(long
the amount of the unit to add to the result, may be negative
amountToAdd
,
TemporalUnit
the unit of the amount to add, not null
unit
)

Implements java.time.temporal.Temporal.plus.

Returns a copy of this time with the specified amount added.

public OffsetTime

Returns:

an OffsetTime based on this time with the hours added, not null
plusHours
(long
the hours to add, may be negative
hours
)

Returns a copy of this OffsetTime with the specified number of hours added.

public OffsetTime

Returns:

an OffsetTime based on this time with the minutes added, not null
plusMinutes
(long
the minutes to add, may be negative
minutes
)

Returns a copy of this OffsetTime with the specified number of minutes added.

public OffsetTime

Returns:

an OffsetTime based on this time with the nanoseconds added, not null
plusNanos
(long
the nanos to add, may be negative
nanos
)

Returns a copy of this OffsetTime with the specified number of nanoseconds added.

public OffsetTime

Returns:

an OffsetTime based on this time with the seconds added, not null
plusSeconds
(long
the seconds to add, may be negative
seconds
)

Returns a copy of this OffsetTime with the specified number of seconds added.

public <
the type of the result
R
>
R

Returns:

the query result, null may be returned (defined by the query)
query
(TemporalQuery<R>
the query to invoke, not null
query
)

Overrides default java.time.temporal.TemporalAccessor.query.

Queries this time using the specified query.

public ValueRange

Returns:

the range of valid values for the field, not null
range
(TemporalField
the field to query the range for, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.range.

Gets the range of valid values for the specified field.

pack-priv static OffsetTime
private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

private long

Returns:

the epoch nanos value
toEpochNano
()

Converts this time to epoch nanos based on 1970-01-01Z.

public long

Returns:

the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative
toEpochSecond
(LocalDate
the localdate, not null
date
)

Converts this OffsetTime to the number of seconds since the epoch of 1970-01-01T00:00:00Z.

public LocalTime

Returns:

the time part of this date-time, not null
toLocalTime
()

Gets the LocalTime part of this date-time.

public String

Returns:

a string representation of this time, not null
toString
()

Overrides java.lang.Object.toString.

Outputs this time as a String, such as 10:15:30+01:00.

public OffsetTime

Returns:

an OffsetTime based on this time with the time truncated, not null
truncatedTo
(TemporalUnit
the unit to truncate to, not null
unit
)

Returns a copy of this OffsetTime with the time truncated.

public long

Returns:

the amount of time between this time and the end time
until
(Temporal
the end time, exclusive, which is converted to an OffsetTime, not null
endExclusive
,
TemporalUnit
the unit to measure the amount in, not null
unit
)

Implements java.time.temporal.Temporal.until.

Calculates the amount of time until another time in terms of the specified unit.

private OffsetTime
with(LocalTime
the time to create with, not null
time
,
ZoneOffset
the zone offset to create with, not null
offset
)

Returns a new time based on this one, returning this where possible.

public OffsetTime

Returns:

an OffsetTime based on this with the adjustment made, not null
with
(TemporalAdjuster
the adjuster to use, not null
adjuster
)

Overrides default java.time.temporal.Temporal.with.

Returns an adjusted copy of this time.

public OffsetTime

Returns:

an OffsetTime based on this with the specified field set, not null
with
(TemporalField
the field to set in the result, not null
field
,
long
the new value of the field in the result
newValue
)

Implements java.time.temporal.Temporal.with.

Returns a copy of this time with the specified field set to a new value.

public OffsetTime

Returns:

an OffsetTime based on this time with the requested hour, not null
withHour
(int
the hour-of-day to set in the result, from 0 to 23
hour
)

Returns a copy of this OffsetTime with the hour-of-day altered.

public OffsetTime

Returns:

an OffsetTime based on this time with the requested minute, not null
withMinute
(int
the minute-of-hour to set in the result, from 0 to 59
minute
)

Returns a copy of this OffsetTime with the minute-of-hour altered.

public OffsetTime

Returns:

an OffsetTime based on this time with the requested nanosecond, not null
withNano
(int
the nano-of-second to set in the result, from 0 to 999,999,999
nanoOfSecond
)

Returns a copy of this OffsetTime with the nano-of-second altered.

public OffsetTime

Returns:

an OffsetTime based on this time with the requested offset, not null
withOffsetSameInstant
(ZoneOffset
the zone offset to change to, not null
offset
)

Returns a copy of this OffsetTime with the specified offset ensuring that the result is at the same instant on an implied day.

public OffsetTime

Returns:

an OffsetTime based on this time with the requested offset, not null
withOffsetSameLocal
(ZoneOffset
the zone offset to change to, not null
offset
)

Returns a copy of this OffsetTime with the specified offset ensuring that the result has the same local time.

public OffsetTime

Returns:

an OffsetTime based on this time with the requested second, not null
withSecond
(int
the second-of-minute to set in the result, from 0 to 59
second
)

Returns a copy of this OffsetTime with the second-of-minute altered.

pack-priv void
private Object

Returns:

the instance of Ser, not null
writeReplace
()

Writes the object using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait